Why is my crontab not working?

So your crontab entry is failing and you don’t know why. How do you proceed?

TLDR

  1. Does your crontab end with an empty line? It must or the last entry will not be considered.
  2. Have you forgotten to set your PATH variable?
  3. Have you setup logging and checked the output for errors?

Suggested Crontab Layout

I suggest writing your crontab entries like below.

Start with these two lines

The first line makes sure that none of those annoying “mails” are getting sent. We will rather setup logging for each of our entries instead.

The second line sets a proper PATH variable. For some reason this is not done automatically and your crontab entry might fail because it can’t find binaries you refer to. I came up with the PATH by logging in as some normal user and typing:

Make use of /usr/bin/logger

I suffix each and every of my crontab entries with something like this:

This sets up logging for the crontab entry using syslog (https://serverfault.com/questions/137468/better-logging-for-cronjobs-send-cron-output-to-syslog). You can now find the recent log entries by typing:

End with empty line

Finally it’s important that your crontab ends with an empty line or the last crontab entry will not be applied.

Helpful External Article

This StackOverflow question has an excellent step by step troubleshooting answer:
https://stackoverflow.com/questions/22743548/cronjob-not-running

By |2017-10-11T13:37:25+00:00October 11th, 2017|Uncategorized|1 Comment

One Comment

  1. […] Time to add this to the crontab! Feel free to read my article about cron jobs first. […]

Leave A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.