Daily cron job not running

A quick overview: I have a script that will daily backup my source code repository from SVN into a tarball for that day. I have tested the script and it works very well as long as I run it as sudo, because of ownership of the output directory.

So the issue is that I want to run this daily, so I put a link to it in the /etc/cron.daily directory. Here are the contents of the directory.

thom@spenser:/etc/cron.daily$ ls -l
total 60
-rwxr-xr-x 1 root root   189 2011-09-14 02:21 apport
-rwxr-xr-x 1 root root 15535 2011-10-06 11:30 apt
-rwxr-xr-x 1 root root   314 2011-08-08 16:57 aptitude
lrwxrwxrwx 1 root root    24 2012-02-28 11:05 backup -> /usr/local/bin/backup.sh
-rwxr-xr-x 1 root root   502 2011-06-08 11:48 bsdmainutils
-rwxr-xr-x 1 root root   256 2011-10-06 04:04 dpkg
-rwxr-xr-x 1 root root   372 2011-10-04 16:50 logrotate
-rwxr-xr-x 1 root root  1353 2011-07-27 07:17 man-db
-rwxr-xr-x 1 root root   606 2011-08-17 09:16 mlocate
-rwxr-xr-x 1 root root   249 2011-06-24 05:36 passwd
-rwxr-xr-x 1 root root  2417 2011-07-01 17:25 popularity-contest
-rwxr-xr-x 1 root root   383 2011-09-30 15:09 samba
-rwxr-xr-x 1 root root  3594 2011-09-19 20:07 standard
thom@spenser:/etc/cron.daily$ 

The problem is that it simply never runs. Here is the permissions for that script:

thom@spenser:/etc/cron.daily$ ls -l /usr/local/bin/backup.sh 
-rwxr-xr-x 1 root root 260 2012-02-28 11:03 /usr/local/bin/backup.sh

Ideas?


Tried this

run-parts --test /etc/cron.daily

Found that my file update.ubuntu did not come up. Also noticed that my file had an extension (has dot in it).

Steps to fix this.

  1. Renamed my update.ubuntu to update-ubuntu
  2. Now again run-parts --test /etc/cron.daily, this time my file came up!

Could be one of several things:

Roots path:

Depending on the commands being run, you may need to expand the root users PATH variable by putting the following line at the top of their crontab file:

PATH=/usr/sbin:/usr/bin:/sbin:/bin

src: https://help.ubuntu.com/community/CronHowto

Or just use full paths to each command in your script: /bin/ls instead of ls for example. (which ls at command line for paths).

There is a strange bug about dots in the filename reported here. Might extend to the file you are linking to, although this seems unlikely.

Are you saving the output from the backup file? Put something like this on the first line, to help determine if it is not running at all or running but failing at some point.

/bin/echo "Attempting to run backup" >> /path-to-home/backup.log

Alternatively try adding the script to the crontab file directly:

sudo -i
crontab -e
[add the next line to the file, then save and exit]
33 15 * * * /usr/local/bin/backup.sh

will run at 15:30 every day if the machine is on. use * * * * * while testing to run once a minute until you get it working.


Grep your syslog for messages like;

crond: (*system*) BAD FILE MODE

the files need to be restricted to (is sufficient) at 644):

chmod 0644 /etc/cron.d/my_crontab