Monday, January 12, 2009

How to debug or test cron script

If your simple cron script (/etc/cron.daily, etc/cron.hourly etc) does not run as expected, do the following:

1. be sure to have '#!/bin/sh' as the first line
2. make sure the script's name does not contains '.'. for example, you should rename 'yourscript.sh' to 'yourscript'.
3. use absolute path if you need to read/write files in the script
4. try run the script in the shell to make sure there is no obvious problem
5. 'run-parts --test /etc/cron.hourly/' will tell you what scripts will run, you should see your script in the list
6. next try to run it like cron does, for example:
cd / && run-parts --report /etc/cron.hourly
7. cron uses syslog for logging. Check your syslog config file ( /etc/syslog.conf) to see where the log is, and check the log for errors.

Ref:
[1] Why are cron.hourly files not running? SOLVED
https://lists.ubuntu.com/archives/ubuntu-users/2007-July/118973.html

Labels: