Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

In my crontab file (sudo crontab -e) I have the following commands:

*/1 * * * * wget -q -O /dev/null
0 7 * * * bash -c "/home/backup/"

The first line executes and works correctly, but the second line isn't working for some reason. However, If I run the script through terminal (./ it runs correctly.

The file is owned by root:root and has 755 permissions.

Within that file is the following bit of code:


/usr/bin/mysqldump -u root -wordpresspassword wordpressusername | /bin/gzip > /home/backup/mysql/wordpress_`date +%m-%d-%Y_%T`.sql.gz
/usr/bin/mysqldump -u root -heskpassword heskusername | /bin/gzip > /home/backup/mysql/hesk_`date +%m-%d-%Y_%T`.sql.gz
/bin/tar cvzf /home/backup/wordpress/wordpress_`date +%m-%d-%Y_%T`.tar.gz /var/www/wordpress/
/bin/tar cvzf /home/backup/hesk/hesk_`date +%m-%d-%Y_%T`.tar.gz /var/www/hesk/
/usr/bin/s3cmd sync -r -P /home/backup/ s3://backups.mysite/
find /home/backup/ -mtime +7 -type f -exec rm {} \;

The script basically backups our MySQL databases and compresses them, backs up our apache sites and compresses them, copies those files to Amazon S3, and then performs a cleanup on the server.

What am I missing here? I've tried a number of things like switching from bash to shell but nothing I've done has worked yet.

share|improve this question
Just to make sure: does sudo bash -c "/home/backup/" work? – Gertjan Oct 4 '12 at 20:50
I'm not familiar with s3cmd but I would assume it requires access to your keyring for upload credentials. This is something that root cannot access if stored in your own keyring. That is just a shot in the dark, could you post the error message from the cron run? – Simon Déziel Oct 4 '12 at 20:58
@Gertjan - Yep, the script runs fine when I run that in terminal. – Kris Anderson Oct 4 '12 at 21:07
@SimonDeziel Yea, s3cmd stores the Amazon key and secret key in a configuration file. We set that up with "s3cmd -config" if I remember correctly. It's processing that command fine and copying the files to S3 as long as I run the script in terminal and not try to automate it using cron. How would I get the error message from cron run? – Kris Anderson Oct 4 '12 at 21:09
Also, why trying to run this as root if you said your own user could run it no problem? Why not simply add this to your user's crontab? – Simon Déziel Oct 5 '12 at 16:00

one workaround is to use shell script to do this:

for (( ; ;))
   sleep 86400
   wget -q -O
   /bin/sh /home/backup/

In above script, I have used sleep 86400 (it's equivalent of one day in seconds). You can configure your interval accordingly.

If you want to run on some server/desktop by logging using ssh, then start/run this script as background process.

share|improve this answer

General tips for debugging crontab:

  1. catch the output.
    • Either redirect it to a file, e.g. { command1; command2; } &>/tmp/joboutput
    • or ensure that the crond send output as email to your mailbox by setting in your crontab.
  2. The shell environment of process invoked by crontab differ from the environment started the same process in a terminal.
    Ensure that all necessary environment variables either specified inside the crontab.
  3. % has a special meaning in the crontab (read carefully man 5 crontab :-)

    The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the crontab file. Percent-signs (%) in the command, unless escaped with backslash (), will be changed into newline characters, and all data after the first % will be sent to the command as standard input. There is no way to split a single command line onto multiple lines, like the shell's trailing "\".

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.