Search code examples
croncron-task

Newly added jobs not running in cron.daily


I'm trying to add a daily cron job to backup a database. I'm able to do it manually by running sh /path/to/file/backup.sh but when I place the file in the cron.daily directory, it doesn't run daily. To try and diagnose it, I created a test file in cron.daily called test just to see if it would run. When I ran run-parts --test /etc/cron.daily, I got the output

/etc/cron.daily/apache2 /etc/cron.daily/apt /etc/cron.daily/bsdmainutils /etc/cron.daily/dpkg /etc/cron.daily/etckeeper /etc/cron.daily/logrotate, etc.

So then I tried copying the content of logrotate to a new file, atest, then ran run-parts again but with the same results.

atest:

#!/bin/sh

test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.conf

Is there something special I need to do to get cron to recognize a newly added task in cron.daily?

This isn't unique to cron.daily, I've tried monthy, weekly, and hourly as well with the same results. I've also tried restarting cron without success. I'm running this on Debian 7.2.


Solution

  • There are a couple of things that can keep files within your /etc/cron* directories from running (e.g. /etc/cron.daily):

    1. Permissions. Make sure the permissions of the files are 0644.

    2. The filename must meet certain conditions. From the documentation: "...they must be entirely made up of letters, digits and can only contain the special signs, underscores ('_') and hyphens ('-'). Any file that does not conform to these requirements will not be executed by run-parts.