- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Run crontab job problem
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2007 02:16 PM
07-22-2007 02:16 PM
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1127866
The stupid solution is :
because the job is unable to run by crontab job and is normal to run manually , is it OK to set before run this crontab job , it su to a specific user "cron_usr" ( this cron_usr will be dedicated as a login a/c to run crontab job) , and I will modify the ~cron_usr/.bash_profile , so that when this user is login , it will run the crontab job automatically , as a result I can make sure this crontab job run the normal user profile , please advise is it OK to do that ? thx
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2007 02:54 PM
07-22-2007 02:54 PM
Solution(It seems it was hangyu's question?)
>because the job is unable to run by crontab job
Do you know exactly why?
If you want to run it under cron, you must source your .profile, either before you run your script or in it.
You shouldn't have to do something as complex as you proposed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2007 03:09 PM
07-22-2007 03:09 PM
Re: Run crontab job problem
> Yes , I lost the password.
Do you know exactly why?
> Still not know the reason , but I guess it should be the difference of .profile .
You shouldn't have to do something as complex as you proposed.
> do you think the solution that I post is possible ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2007 04:15 PM
07-22-2007 04:15 PM
Re: Run crontab job problem
I tried this method , I guess the theroy is OK , but not work when I try to use "su - cron_usr" in the crontab job , what I want is just to run a crontab job , this crontab job will do the login ( userid is cron_usr ) , this user will do the script that I want when login , can advise how to do this ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2007 06:22 PM
07-22-2007 06:22 PM
Re: Run crontab job problem
I tried to rlogin stead su , but still not work , how to run a crontab job that will do the user login ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2007 06:43 PM
07-22-2007 06:43 PM
Re: Run crontab job problem
I tried to write a scrip /tmp/script1
#vi /tmp/script1
rlogn localhost -l cron_usr
#vi ~cron_usr/.profile
my_script
if I run this script manually , it is OK , but if I run it by crontab job , it is not work , so I think run manully and by crontab is different , can advise how can I make it work ?
thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2007 08:32 PM
07-22-2007 08:32 PM
Re: Run crontab job problem
why don't you make a copy of your command - use one for running manually, in the other revers all changings you've made and run it with cron, as it worked before?
By the way - which linux are you using?
Volkmar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2007 08:37 PM
07-22-2007 08:37 PM
Re: Run crontab job problem
I use Redhat Ent. 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2007 09:30 PM
07-22-2007 09:30 PM
Re: Run crontab job problem
thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2007 11:13 PM
07-22-2007 11:13 PM
Re: Run crontab job problem
why don't you make a copy of your command - use one for running manually, in the other revers all changings you've made and run it with cron, as it worked before?
> sorry , I am not too understand what is that mean ,
but for simply , I just want to setup a crontab job , when run this job , it will login the system ( just like a telnet , ssh etc ) , is it possible ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2007 11:18 PM
07-22-2007 11:18 PM
Re: Run crontab job problem
check your previous thread, where the cron job worked!
For Linux you should ask here:
http://forums1.itrc.hp.com/service/forums/familyhome.do?familyId=118
HTH
Volkmar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2007 11:44 PM
07-22-2007 11:44 PM
Re: Run crontab job problem
did you try this?
#*******************************************************************************
# min|hour |day |month|day |script
# | |of mo| |of wk|
#----|-----|-----|-----|-----|--------------------------------------------------
#*******************************************************************************
00 21 * * * echo "/home/yogeeraj/myscript.sh; exit"|su - cron_usr 1>/home/yogeeraj/logfiles/output_script.crn 2>/home/yogeeraj/logfiles/error_script.crn
#*******************************************************************************
# END OF TABLE day0->Sunday day6->Saturday
#*******************************************************************************
Kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2007 11:46 PM
07-22-2007 11:46 PM
Re: Run crontab job problem
00 21 * * * echo "/home/cron_usr/myscript.sh; exit"|su - cron_usr 1>/home/cron_usr/logfiles/output_script.crn 2>/home/cron_usr/logfiles/error_script.crn
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2007 12:23 AM
07-23-2007 12:23 AM
Re: Run crontab job problem
You can't recover the password because you don't know the old email alias or it no longer exists?
>but I guess it should be the difference of .profile.
Then source that .profile in your script.
>do you think the solution that I post is possible?
As I said, why do something that complex.
>"su - cron_usr" in the crontab job
This will ask for a password if not root. You can't do that in a cronjob.
>this crontab job will do the login (userid is cron_usr), this user will do the script that I want when login, can advise how to do this?
You can set up a crontab for cron_usr. Let that do the work.
>how to run a crontab job that will do the user login?
You can't unless root.
#vi /tmp/script1
rlogin localhost -l cron_usr
>#vi ~cron_usr/.profile
my_script
You don't want to put anything executable like that in .profile.
>can advise how can I make it work?
You create a crontab entry for cron_usr to execute ~/my_script.
In my_script you source .profile:
. ~/.profile
>Volkmar: why don't you make a copy of your command - use one for running manually, ...
There is no reason you can't use one script for both.
>I just want to setup a crontab job, when run this job, it will login the system (just like a telnet
There is no need to login to the system like telnet, just "login" like crontab.
>yogeeraj: echo "/home/cron_usr/myscript.sh; exit"|su - cron_usr
It would be much easier to fiddle with the script than to make the crontab entry so complex.
Also, root can use:
su - cron_usr -c "/home/cron_usr/myscript.sh"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2007 12:35 AM
07-23-2007 12:35 AM
Re: Run crontab job problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2007 04:29 AM
07-23-2007 04:29 AM
Re: Run crontab job problem
when run echo "/home/yogeeraj/myscript.sh; exit"|su - cron_usr , it pop "standard in must be a tty" . thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2007 05:25 AM
07-23-2007 05:25 AM
Re: Run crontab job problem
the following should on the same line:
00 21 * * * echo "/home/cron_usr/myscript.sh; exit"|su - cron_usr 1>/home/cron_usr/logfiles/output_script.crn 2>/home/cron_usr/logfiles/error_script.crn
so that the standard output and error are redirected to the desired files.
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2007 01:02 PM
07-23-2007 01:02 PM
Re: Run crontab job problem
I believe we mentioned in your previous thread that you need to add "set -x" to your profile so you can find what command is doing that.
Clay mentioned: the fact that stdin, stdout, and/or stderr are terminal devices ...
Typically this is a common mistake in .profile where the tty commands aren't guarded by checks:
# Set up the terminal:
if [ "${-%%*i*}" != "$-" ]; then
/bin/stty erase "^H" kill "^X" intr "^C" eof "^D" susp "^z"
fi
Similarly for ttytype, tset or resize.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2007 01:13 PM
07-23-2007 01:13 PM
Re: Run crontab job problem
/usr/local/bin/user_mickey_env.sh and then both your cron'ed script AND mickey's .profile source this file using the "." (dot)operator ".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2007 01:43 PM
07-23-2007 01:43 PM
Re: Run crontab job problem
A smarter way to do it is to not do su at all. Just add a crontab entry for mickey.
>What you do is create a file something like
/usr/local/bin/user_mickey_env.sh
It seems like the right thing to do is fix your .profile. That way you don't come back next year with the same problem on a different script.
(I'm not sure why you would want to put mickey specific stuff in /usr/local/, rather than in ~mickey/.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2007 02:01 PM
07-23-2007 02:01 PM
Re: Run crontab job problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2007 02:06 PM
07-23-2007 02:06 PM
Re: Run crontab job problem
I suppose you are correct if this user is really a dummy user for something like Oracle or SAP, where it is done on behalf of the system.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2007 03:00 PM
07-23-2007 03:00 PM
Re: Run crontab job problem
do you mean add "su - cron_usr" to
/usr/local/bin/cron_usr_env.sh , I tried this method , but it is OK to run at shell ( manual run ) but not work to run by crontab job ,
thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2007 02:45 PM
07-24-2007 02:45 PM
Re: Run crontab job problem
I got many suggestions but I still not fix the problem yet ,
as my previous message , is it possible to run a batch job (eg. /tmp/script1) that will do the login ( eg. ssh , telnet , rlogin )
for example :
#vi /tmp/script1
su - cron_usr
#vi ~cron_usr/.profile
my_script
when run the crontab job ( /tmp/script1) , it will su to cron_usr , then it will run my_script .
thx in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2007 03:23 PM
07-24-2007 03:23 PM
Re: Run crontab job problem
You can do it as root.
>for example :
/tmp/script1:
su - cron_usr
~cron_usr/.profile:
my_script
when run the crontab job (/tmp/script1), it will su to cron_usr, then it will run my_script .
I did all of this and except for the error messages from /etc/profile, it worked.
The crontab stderr had:
ttytype: couldn't open /dev/tty for reading
stty: : Not a typewriter
The crontab stdout had copyrights, /etc/motd
and "logout" upon the EOF in .profile.
Basically cron does NOT want/expect you to do "su -".
This is an awfully long way to go when you can just fix the script to source what it needs out of a modified .profile.