crontab not working

Shell = ksh

Hi all,

I scheduled an automated job on my application server like below,

30 13 * * 1-5 $HOME/my_script.sh

However the script was not executed as expected. Any reason that may cause this to happen?

change to:
30 13 * * 1-5 $HOME/my_script.sh > $HOME/my_script.log 2>&2
to get stdout and stderr output.
I have seen this before - where the environment is NOT set up correctly when running from crontab
You may need to set up expected environmental variables manually.

you need to take the logs for the cron job . Most likely its a env variable issue as cron does not set your env variables by default. You need to check the cronrun log file to find the details . Defile the exact path instead of defining a variable.($HOME/my_script.sh )

 
30 13 * * 1-5 $HOME/my_script.sh >> /var/log/cronrun 2>&1
change to
30 13 * * 1-5 /USR/dir/my_script.sh >> /var/log/cronrun 2>&1
 
1 Like

If you are using any files or directories inside your my_script.sh, then use the absolute path ( from the root / )

Yeah, like you said, I defined some variables in that particular script. Probably these variables are not recognised by the Unix environment? So what should I do in such cases?

Manually define them and then export?

This type of problems occur mainly because of improper environment. Please provide the script lines so that we can dig further and suggest which environment variables to use..
Thanks

On a slightly different path, how did you create the cronjob?
Did you set the shell environment variable to vi? Did you run crontab -e to modify the cronjob file?