2

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:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# 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?

2
  • For a command that simple the shell should not matter. In fact, you're doubling up on it since it will now use sh to run bash to run backup. You should be able to just skip running the shell yourself and be fine. Sep 5, 2012 at 22:35
  • ServerFault is usually be a better place for this sort of question. This one might be migrated by a moderator soon. Sep 5, 2012 at 22:40

2 Answers 2

1

The most common thing I run into with cron not running something is that without a MAILTO set, if the command produces output cron will immediately stop it. Or possibly it tries to write to stdout and encounters a SIGPIPE. Not sure the exact mechanism.

Add MAILTO=<your email address> and give that a try. Alternatively, write both stdout and stderr out to a log file by appending >>/var/log/backup 2>&1 to the cron line you already have.

1
  • I have added MAILTO=<my_email_address> to /etc/crontab file.But I didn't receive a mail.And >>/var/log/backup 2>&1 method didn't get a backup result.It is strange. Sep 6, 2012 at 1:37
0

crontab is a config file. Why not edit it and change sh to bash?

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
1
  • I have edited it,but return a same result:-( Sep 6, 2012 at 1:32

You must log in to answer this question.

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