Softpanorama

May the source be with you, but remember the KISS principle ;-)
Home Switchboard Unix Administration Red Hat TCP/IP Networks Neoliberalism Toxic Managers
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and  bastardization of classic Unix

Cron Troubleshooting

News Cron and Crontab commands Recommended Links Reference Macros at and batch commands  Ordinary users in SLES 11 and 10 are denied access to cron
cron.allow cron.deny Troubleshooting Admin Horror Stories

Tips

Humor Etc

Like with any troubleshooting problem you need to collect evidence to discover the root cause.

Then you need to go through the quick checklist:

  1. Do you have proper line in crontab? There should be five fields before invocation of the script or program.

  2. Are there any errors in standard logs? Check the cron log, usually /var/log/cron.log or /var/log/messages for errors
  3. Are you using relative paths? If your cron job is executing a script of some kind, you must be sure to use only absolute paths inside that script.
  4. Does you script has executable permissions?  Please be sure the script in question is executable. In the case script is writing to a file or folder, they should better be writable.
  5. Was your command ever invoked? Test your entry in crontab by changing the command to something like: echo "this is a test" > somefile  or touch /tmp/test
    For example you can change your invocation line to:
     * * * * * /bin/echo "this is a test" >> /tmp/test`date +"%y%m%d_%H%M"`

    See if it creates files each minute. Then replace /bin/echo "this is a test" back with your command and see what happens.
     

  6. Is your command working at all? Sometimes the script was changes and now has errors that prevent its execution. Often your script makes some implicit assumptions about environment which do not hold in case of running from cron. You can check this situation in two steps:
  7. If your cron job is running as a regular user, is this user allowed to run cron jobs? If a user was not allowed to execute jobs when their crontab was last edited, just adding them to the allow list won't do anything. The user needs to re-edit their crontab after being added to cron.allow before their jobs will run.
  8. The "%" character is used as newline delimiter in cron commands. If you need to pass that character into a script, you need to escape it as "\%".
  9. Are there any dead.letters? cron usually sends mail when there's a problem; check your mail and also look for ~/dead.letter.

Top Visited
Switchboard
Latest
Past week
Past month