LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Crontab for automated backup --> not running (https://www.linuxquestions.org/questions/linux-newbie-8/crontab-for-automated-backup-not-running-4175453596/)

shivaa 03-12-2013 07:52 AM

Quote:

Originally Posted by Wover (Post 4909922)
Hurray! It works :). In the last edits I left out username variable in the crontab lines. Thanks to all!

Following should have worked:
Code:

0 3 * * * "cd /var/scripts; ./serverbackup.sh > /tmp/backup_logs"
OR
0 3 * * * "/var/scripts/serverbackup.sh > /tmp/backup_logs"

Did you try this? If not, what did you do?

Wover 03-12-2013 07:57 AM

So:

1) Get the $PATH for the user you are running the script with and paste it under PATH in the crontab file
2) put /bin/sh in front of the command and don't forget the username either

Troubleshooting steps:

1) output some command to a file every minute, for example * * * * * root env > /tmp/env_output
2) If no output, check if crond is running
3) If output, try running the command manually from the shell and correct any errors that occur

chrism01 03-12-2013 08:56 PM

If the script has executable perms and has the first line '#!/bin/bash' (normal setup), then no need for eg /bin/sh in cron entry.
Speaking of which, if you use that approach, select the exact shell you want eg either sh or bash; they're not the same thing.
For portability I ALWAYS put the correct one in the first line of the script and use execute perms.
Also, I'd put the PATH inside the script for the same reason. It makes cron less cluttered and not all scripts need the same PATH.


All times are GMT -5. The time now is 02:57 AM.