Blog Tags: 

How to debug a broken cron job

I just fixed a broken cron job. It turned out it was a PATH issue. By default cron doesn't have /usr/local stuff in the PATH.

Tips on how to debug cron:

  • change the schedule for the cron job so it runs every minute. It's harder to debug something that happens infrequently.

  • Make sure syslog sends cron logs to /var/log/cron.log. On one of our servers this line was commented out for some reason:

    cron.*                          /var/log/cron.log
    
  • Follow the log file to track cron's activity. See what jobs are being executed, and when:

    tail -f /var/log/cron.log
    

    This is how I found out my cron job was running, though I still didn't know why it wasn't working.

  • Make sure the cron job user can receive mail. If a cron job has output the system will send the user mail. In our case we were running this job as the newly created user. One server relays all e-mail to another server, and the e-mail bounced because the new user doesn't exist on the mail relay. Aliasing the new user to user admin solved this problem.

    Now I was getting e-mail from the broken cron job and could see that there was a PATH issue.

Add new comment