I have setup cronjob for root user in ubuntu environment as follows by typing crontab -e
34 11 * * * sh /srv/www/live/CronJobs/daily.sh
0 08 * * 2 sh /srv/www/live/CronJobs/weekly.sh
0 08 1 * * sh /srv/www/live/CronJobs/monthly.sh
But the cronjon do not run. I have tried checking if the cronjob is running using
pgrep cron
and that gives process id 3033.The shell scrip is calls python file and is used to send email. Running the python file is ok. There's no error in it but the cron doesn't run. The daily.sh file has following code in it.
python /srv/www/live/CronJobs/daily.py
python /srv/www/live/CronJobs/notification_email.py
python /srv/www/live/CronJobs/log_kpi.py
Sometimes the command that cron needs to run is in a directory where cron has no access, typically on systems where users' home directories' permissions are 700 and the command is in that directory.
Another reason crontab will fail: Special handling of the
%
character.From the man file:
In my particular case, I was using
date --date="7 days ago" "+%Y-%m-%d"
to produce parameters to my script, and it was failing silently. I finally found out what was going on when I checkedsyslog
and saw my command was truncated at the%
symbol. You need to escape it like this:See here for more details:
http://www.ducea.com/2008/11/12/using-the-character-in-crontab-entries/