Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

crontab setup

Status
Not open for further replies.

new2unix

Programmer
Feb 5, 2001
143
US
Hi,

I am using IBM AIX and have the following line in my crontab:

0,5,10,15,20,25,30,35,40,45,50,55 2-23 * * * /usr/testgate/scripts/myscript.sh

Basically, I want to run this script every 5 minutes between 2 am to 11 pm everyday. But I am not sure if the job gets executed at all because I am not seeing the same result compared to when I manually executed the scripts. Did I set up the crontab incorrectly?

I did a ps -ef | grep cron and saw the following:

root 11652 1 0 Aug 15 - 3:46 /usr/sbin/cron

This should mean the cron process is running.

Thanks

Mike
 
Hi New,
If you are seeing result that means cron is running. You are getting different result evertime that is not cron's falut it is your script or your input.

Patel
 
your command ps -ef|grep cron is showing that cron is running, not that your script is. You should try ps -ef|grep myscript.sh to see if it is running. Also, the output from your script should be re-directed to a log as well as STNDERR. try adding this to the crontab.

0,5,10,15,20,25,30,35,40,45,50,55 2-23 * * * /usr/testgate/scripts/myscript.sh >> /tmp/myscript.log 2>&1

crowe
 
Remember, when cron runs your script, it doesn't inherit your environment. So, your script will have to execute your .profile, or explicitly set whatever environmental variables it needs.

Alternatively, set up root's crontab to run a script which then does

su - user -c "/path/command" TandA

One by one, the penguins steal my sanity.
 
Hi Ayjaycee,

You hit it right on the nail. I was wondering about the different environment when the script is executed by cron. Although I am still not sure how to fit the "su - user..." into the crontab, what I did was, in the script itself, added the absolute path to one of the line that calls a binary to retrieve a flag:

result_var=`/absolute_path/another_binary_program` | grep "something"

I think the problem was the script wasn't able to locate the binary without the proper path info when executed by cron. Problem solved. :)

Thanks

Mike
 
"Although I am still not sure how to fit the "su - user..." into the crontab" :-

You don't put the su - user in the crontab, you put a script (giving the complete path to it) in there & thge script itself has the su - user command in it.

HTH TandA

One by one, the penguins steal my sanity.
 
Sorry amuck, I'm talking rubbish :~/ - now I see what you mean. Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top