Debian Cron Not Running Daily, Weekly, Monthly Jobs?

Some VPS vendors, when they provision your server, will install a very bare-bones OS. Debian’s default /etc/crontab includes lines to run the scripts in /etc/cron.{daily,weekly,monthly}, and it’s encouraged to place additional scripts in those directories to run jobs on a simple schedule.

I recently noticed that a backup script on a customer’s server wasn’t running, and it took me several minutes of digging to discover the reason. These special script directories are ignored unless you install anacron:

25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

Update: It’s a good idea to verify that something you blog about is actually true. In this case, my original advice was completely wrong.

Anacron is useful for systems that are not powered on all of the time. It allows jobs to “catch up” when the system comes back up, so that a daily job runs closer to once a day, even if the system is off or sleeping when cron normally runs it. It didn’t solve my problem.

Reading the man page for run-parts, on the other hand, did.

If neither the –lsbsysinit option nor the –regex option is given then the names must consist entirely of upper and lower case letters, digits, underscores, and hyphens.

Note that neither of these options is used in Debian’s crontab. My job wasn’t running because I did not remove the .sh suffix from the script name. A simple rename fixes this problem.