0

So I've created a backup script that tar's up files, rsyncs them to a remote server, and removes the tar afterwards. I've manually tested the file and it runs, however I cannot get it to run via cron.

Script Details:

-rwxr-xr-x 1 root   root    792 Sep 21 18:44 backup.sh

Crontab Details:

* 04 * * * sh /home/user/scripts/backup.sh >/dev/null 2>&1

Syslog Output:

Sep 23 16:25:01 user CRON[15244]: (root) CMD (sh /home/user/scripts/backup.sh >/dev/null 2>&1)

I've attempted to run just /home/user/scripts/backup.sh without the sh in front also, however it gives the same syslog output.

Any help on this is appreciated. Without any real details in the syslog, I've run into a roadblock.

  • 1
    Maybe you should stop sending the output to /dev/null and see what it contains? – muru Sep 24 '15 at 3:39
0

The command is running since you're seeing it in syslog. I imagine you don't have a hashbang at the top of your shell script, are using bash syntax while running the job in sh, or are using a non-fully-qualified path (using just echo instead of /bin/echo). There's this answer to that problem: https://unix.stackexchange.com/questions/94456/how-to-change-cron-shell-sh-to-bash

  • I have altered crontab to have SHELL=/bin/bash at the top and adjusted the actual cron to remove the 'sh'. Still no dice. – Jon Edney Sep 23 '15 at 22:17
  • Crontab suggests the format should be: # m h dom mon dow user command but yours doesn't have a user * 04 * * * root sh /home/user/scripts/backup.sh >/dev/null 2>&1 – Ryan Attard Sep 23 '15 at 22:25
  • @JonEdney you add a shbang #!/bin/bash at the top, not SHELL= – Panther Sep 24 '15 at 2:58
  • @JonEdney cron runs with a minimal shell and minimal envriontal variables. Use the FULL PATH TO BINARIES – Panther Sep 24 '15 at 16:40
0

your cron job will create backup every day 04 AM every minute . your are creating backup every minutes so it may be your backup process take more than 1 minute. change first * to either 0 or some other. if you want to create backup once a day then use

0 04 * * * /home/user/scripts/backup.sh >/dev/null 2>&1

it will create backup everyday 04 AM.

or if you want to create backup every four hour then use like

0 */4 * * * /home/user/scripts/backup.sh >/dev/null 2>&1

no need to add sh. make sure you are giving full path of script.

you can learn more from How do I set up a Cron job? or any other blogs. also make sure you are setting this as a root user. i can't talk about your shell because i don't know what you written in shell.

go through Reasons why crontab does not work this is good explanation to find basic crontab issues. also you can see my answer for some help here

  • Thank you. I've altered my initial script, however as I've been working on this I've been editing the cron to run at specified times and still no change. – Jon Edney Sep 24 '15 at 16:13
-1

Try to restart cron service.

/etc/init.d/crond start

and then check your process running or not.

  • Restarting the cron service was one of my first troubleshooting actions. – Jon Edney Sep 24 '15 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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