LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Cron backup script stops running after a few days (http://www.linuxquestions.org/questions/linux-server-73/cron-backup-script-stops-running-after-a-few-days-632947/)

brokenpromises 04-04-2008 06:49 AM

Cron backup script stops running after a few days
 
I set up a cron script to do backups at 3AM every night, and it ran fine for a few days, then stopped. Here are the contents of the script:

Code:

#!/bin/sh

# Auth Details for FTP
USERNAME="<SNIP>"
PASSWORD="<SNIP>"
SERVER="<SNIP>"

# Create backup
tar cjf /tmp/backup/"backup_"$(date +"%d_%m_%Y").tar.bz2 /var/www*

# For testing - instant backup creation
# touch /tmp/backup/"backup_"$(date +"%d_%m_%Y").tar.bz2

# File to upload
FILE=""backup_"$(date +"%d_%m_%Y").tar.bz2"

# Upload file to backup server
ncftp -u $USERNAME -p $PASSWORD $SERVER<<EOF
mput /tmp/backup/"backup_"$(date +"%d_%m_%Y").tar.bz2
quit
EOF

rm /tmp/backup/"backup_"$(date +"%d_%m_%Y").tar.bz2

It isn't the cleanest, but I'm a novice user so :p

and the line in crontab -e that I put in:

Code:

0 3 * * * /root/bkup.sh
Any ideas why this happens?

blacky_5251 04-04-2008 06:55 AM

Are there any errors in /var/log/cron? Can you see cron attempting to run the script - i.e. has cron died or is there a problem with the script.

Try changing your cron entry so errors are logged:-
Code:

0 3 * * * /root/bkup.sh > /root/bkup.log 2>&1
Has root received mail from cron about the script not working?

colucix 04-04-2008 07:02 AM

You can also look at the mail of the owner of the crontab (that one accessed by the mail command) since the standard error and standard output of cron jobs are redirected there by default (if not explicitly redirected to a file as suggested by blacky_5251).

Edit: uh... sorry, I didn't notice blacky_5251 has already suggested.

jlinkels 04-04-2008 07:17 AM

Be sure to redirect any output created by the script to somewhere. That is, if you run the script in the console, and you see any output, it should be redirected to either a log file or to /dev/null.

I don't know exactly why, but if you produce output (either to stdout or stderr) and it is going nowhere while you run a job in background it stops after certain time.

jlinkels

Gran_Maestre 04-04-2008 02:31 PM

file tar.bz2 is generated?

brokenpromises 04-05-2008 06:30 AM

Quote:

Originally Posted by Gran_Maestre (Post 3110838)
file tar.bz2 is generated?

Sure is, however that isn't the problem.

It appears the problem was in that I didn't redirect the output of the file to anywhere. After redirecting to /dev/null it appears to be running again. Strange.


All times are GMT -5. The time now is 04:15 PM.