OS : Ubuntu 12.04

Now I want to use Backup and Whenever gem to automatic backup my database. When I connect the server by ssh as an added user to run backup perform -t my_backup,it works well.But the cron file:

0 22 * * * /bin/bash -l -c 'backup perform -t my_backup'

can't run at 22:00. When I use cat /etc/crontab check the cron's config file,it is:


# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
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 )

The /bin/bash and /bin/sh are different.What's the reason?How to do?

  • What do you call “the cron file”? Is that the output of crontab -l? If you add a job * * * * * echo test, do you receive an email every minute (remember to turn it off after a couple of minutes)? Commented Sep 5, 2012 at 22:00
  • I have add MAILTO=<my_email_address>,but haven't receive a mail.Even added the * * * * * echo test. Commented Sep 6, 2012 at 1:47

3 Answers 3


The special crontab file /etc/crontab has a slightly different format in that the sixth field must be the user the cron job will be run as. So if you want to put your job into that file, you must insert a user name between * and /bin/bash to match the format. Something like:

0 22 * * * root /bin/bash -l -c 'backup perform -t my_backup'

replacing root with whatever user name you really want to use.

  • yep, either that or JZ should add it to the user's own crontab. and for completeness, crontab files in /etc/cron.d/ have the same format as /etc/crontab.
    – cas
    Commented Sep 5, 2012 at 3:55
  • Thank you very much.I have run whenever with rails user which I created by root.I have try your method to add root or rails user name between the * and /bin/bash,but it still doesn't work:-( Commented Sep 5, 2012 at 4:05
  • @JingqiangZhang If the command is running and failing, cron should be mailing the user the error messages. Also, cron itself should be logging its activities somewhere, probably in /var/log.
    – Kyle Jones
    Commented Sep 5, 2012 at 4:32
  • The log file /var/log/cron.log has: Sep 3 22:00:01 domain-name CRON[20833]: (rails) CMD (/bin/bash -l -c 'backup perform -t my_backup'),I don't know why there isn't any result.Also,I didn't receive a mail by cron. Commented Sep 5, 2012 at 5:24

Try to build a script with the backup command you want to execute, and then call this in the crontab like:

0 22 * * * (cd <absolute-path-of-directory> && ./script.sh >>script.log 2>&1)

In this script I recommend first of all a line like

echo "`date '+%Y%m%d %H%M%S':`: $0 started"

So you can see that cron is executing it and concentrate on the command. Reasons why scripts don't run under cron that are normally executing fine are often find in the different environment that is used under cron.


i also experienced the same few weeks ago. i was trying to copy and overwrite the crontab file. even though all the parameters were proper, cron was not running as expected. when i removed and copied the same file, it was working fine.. just try the same..

however i did not understand the reason it did not work when i tried to overwrite that file..

  • Thank you for your suggest,but I have no luck. Commented Sep 5, 2012 at 6:19
  • The safe way to make changes to the crontab is through crontab -e, which will open an editor for you and afterwards reload the config. cron is under no obligation to monitor if changes have been made behind its back. Commented Sep 5, 2012 at 6:45

You must log in to answer this question.

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