1832275 Members
1893 Online
110041 Solutions
New Discussion

Re: cron not running

 
Ragni Singh
Super Advisor

cron not running

Hi all, have a dilemma here. I have a cronjob that runs sucessfully on the command line but it fails out of cron. Does anyone know what could be causing this issue? I have a system going in production so I need to get this resolved right away. Thanks for your time and points will be assigned.
9 REPLIES 9
Steven E. Protter
Exalted Contributor

Re: cron not running

Different behavior in and out of cron is almost always due to differences in the environment.

add a line to the script:

env > /tmp/$env.txt


Let cron run it and then run it manually.

diff the two files.

There will be different and when corrected the behavior should be consistent.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Cem Tugrul
Esteemed Contributor

Re: cron not running

Hi,
Check your env,Cron runs in posix born shell.Also check your syntax when you crontab -e.

Good Luck,
Our greatest duty in this life is to help others. And please, if you can't
Cem Tugrul
Esteemed Contributor

Re: cron not running

Please also have a look;

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=5398

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=449988
Our greatest duty in this life is to help others. And please, if you can't
NiCK_76
Respected Contributor

Re: cron not running

Hi Chand,

I suggest you can export environment values in the crontab to have a try. For example:
crontab -e
====================
export xxx=xxxx
*/5 * * * * /test.sh
=====================

NiCK
just for fun
Mobeen_1
Esteemed Contributor

Re: cron not running

Sanjith,
Its most of the time as mentioned by others due to environment not being set properly.
If you are having problems trying to figure it out, post it here and the one having sharp eyes will get it first :)

rgds
Mobeen
Jan Sladky
Trusted Contributor

Re: cron not running

Hi Sanjit,

as all mentioned before, set all needed variables before job is running

bellow is example for my Oracle env.
#!/bin/bash
export ORACLE_SID="SMS"
export TWO_TASK=SMS
export ORACLE_HOME="/opt/Oracle"
export PATH="/usr/bin/:$ORACLE_HOME/bin:"

rgds Jan
GSM, Intelligent Networks, UNIX
Ragni Singh
Super Advisor

Re: cron not running

This is the problem. we have elm installed in /usr/local/bin/elm. When I run the script from the command line, it is able find elm and it runs. When I run the same thing out of cron, my output says it is not able to find elm...elm: command not found. The user has a search patch in his profile to search /usr/local/bin.

Also I don't know if it makes a difference but my elm permission is the following..

-rwxr-sr-x 1 bin mail 325106 Mar 10 13:57 elm

Any help is appreciated and points will be assigned.
Ragni Singh
Super Advisor

Re: cron not running

Hello, thanks for all the time and help. Actually to make it work, I ended up copying elm to /usr/bin.
Ragni Singh
Super Advisor

Re: cron not running

moved elm to /usr/bin.