Operating System - HP-UX
1832506 Members
4599 Online
110043 Solutions
New Discussion

crontab job doesn't work properly

 
SILVERSTAR
Frequent Advisor

crontab job doesn't work properly

Hello,

I have a script lauched by crontab that doesn't work because some variable are not set, but the .profile is correct, moreover by command line it works properly, which is the issue ?
Cron:
27 16 * * 0,1,2,3,4,5 /QA/QA/JOB/manudt.sh

The script:
$ cat /QA/QA/JOB/manudt.sh
#
# A G G I O R N A M E N T O D A T E D O C U M E N T I
#
echo $HOME
. /QA/QA/JOB/.profile
echo $HOME
echo $COBDIR
/QA/QA/OGG/UTMANUDT


The output: cat /QA/QA/JOB/manudt.out
/QA/QA/JOB
Not a terminal
stty: : Not a typewriter
stty: : Not a typewriter
/QA/QA/JOB/manudt.sh[5]: COBDIR: Parameter not set.
logout

Thanks
Angelo
3 REPLIES 3
Umapathy S
Honored Contributor

Re: crontab job doesn't work properly

Angelo,
The cron env is different from a shell. .profile wont be run on a cron env. So you have to make sure that the env var are exported The script which is called from cron should have those env var exported or the full path for all the commands should be used.

HTH,
Umapathy
Arise Awake and Stop NOT till the goal is Reached!
curt larson_1
Honored Contributor

Re: crontab job doesn't work properly

cron invokes the command from the user's HOME directory with the POSIX shell, (/usr/bin/sh). It runs in the c queue (see queuedefs(4) ).

cron supplies a default environment for every shell, defining:

HOME=user's-home-directory
LOGNAME=user's-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh



Users who desire to have their .profile executed must explicitly do so in the crontab entry or in a script called by the entry.
twang
Honored Contributor