Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've made a script that backs some files up and puts them in a folder,

When I do

sudo /data/backups/scripts/nightlybackups.sh

It works, I just want to make it a cron job so that it runs every night

I have this line in /etc/crontab

30 23 * * * /bin/bash /data/backups/scripts/nightlybackups.sh

The script leaves a log file, indicating when it was called, and I can see that the cron never calls this script, am I doing something wrong?

This is a centos machine, here is the output of uname -a

Linux venus 2.6.32-279.1.1.el6.x86_64 #1 SMP Tue Jul 10 13:47:21 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
share|improve this question
1  
There should be no need to call bash. Try adding #!/bin/bash in the first line of your file instead. Check the cron log for more information and enable e-mailing the execution output to you if you want. – zmode Oct 17 '12 at 17:30
up vote 3 down vote accepted

When adding entries to /etc/crontab you must include a username.

So something like

30 23 * * * root /bin/bash /data/backups/scripts/nightlybackups.sh

Past that you need to examine your scripts use of environment variables. Cron has a very limited environment/PATH/etc. Some of the variables you have set in your interactive shell probably won't be set the same when the script is run from cron.

share|improve this answer
    
It worked, many thanks – user893730 Oct 26 '12 at 14:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .