How can I tell if my hourly cron job has run?
You should look in your /var/log/syslog
log file. If a cron has run, it would have a line like:
Jun 11 19:09:01 penguin CRON[17376]: (root) CMD ( [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2>/dev/null \; -delete)
Jun 11 19:17:01 penguin CRON[17799]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
For troubleshooting tips, see https://help.ubuntu.com/community/CronHowto#Troubleshooting_and_Common_Problems
One major pitfall to cron is cron runs in an extremely limited shell environment, as a result a lot of variables aren't exported in to the environment, mainly $PATH. Make sure you use all absolute paths to executable, including common functions like echo
, uptime
, date
, etc all need to use full paths (/bin/echo
, /bin/date
, /usr/bin/uptime
). To determine the path to an executable, you can use the which
command like so: which echo
- this will show you the full path to that tool.
Try changing the first line of your script (the interpreter) to:
#!/bin/bash
I've also had problems in the past, with environment variables and PATH issues. After changing the interpreter to bash
my issues were gone.