Cron Checklist
Short list
- Schedule syntax
- Empty line
- User has permissions
- Shell command combination problems
- Command works as the user running cron
- cron daemon is running
- cron runs scripts
- Programs are defined with full path
- Programs might use other programs which are not in PATH
- Job isn't scheduled only one minute in the future
- Job is run from right directory
- Check mail
- Check logs
- User has a shell defined
- Percent signs
- Day of week and day of month combo
- User
- Environment
- Timezone
Verbose list
- Refer to the manual to check the correct scheduling syntax
- Make sure there's an empty line at the end
- Make sure the user has permissions to run cron jobs
- Make sure you're not assigning environment variables just once while using shell
constructs which combine or separate the commands, such as &&, || or ;
- This will only have FOO=bar assigned in the first script.sh
- FOO=bar sh script.sh && sh script.sh
- Check that the command works as the user who will run the job
- Check that cron daemon is running
- Test that the cron job is actually ran by using a test script which writes into a temporary file
- Verify that programs are defined with their full path, e.g., /bin/grep instead of just grep
- cron runs with a very minimal environment so it might not have a proper path set
- a program might also run another program which is not in PATH
- Setting the cron job just one minute to the future does not work with many implementations
- Check that the cron job is run from the right directory (cd to the proper directory in the job if needed)
- Check if cron has sent mail about its failure
- Check logs
- Make sure the user who will run the job has a shell defined
- Look out for per cent signs (%)
- Check that you're not setting day of week and day of month together. There's a bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=460070
- "The other fields are
combined with a logical AND (ie: month AND day of month AND hour AND
minute), whereas the day of month and day of week fields are combined
with a logical OR." Use a shell command to check the date: "`date +w`" -eq 5 &&
- Check the user who is running the cron job
- Look at the profiles and other shell resource files
- Check the environment
- Create a cron job which will dump the environment to a file (env > /tmp/cron-environment command) and maybe diff it with a working environment
- Try the command out on the terminal with a regular Bourne Shell (started with the command sh)
- Cron could be run as a different user who has a different timezone. Also check environment variable CRON_TZ