-   Linux - Server (
-   -   Cron backup script stops running after a few days (

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:



# Auth Details for FTP

# 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
mput /tmp/backup/"backup_"$(date +"%d_%m_%Y").tar.bz2

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:


0 3 * * * /root/
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:-

0 3 * * * /root/ > /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.


Gran_Maestre 04-04-2008 02:31 PM

file tar.bz2 is generated?

brokenpromises 04-05-2008 06:30 AM


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:17 AM.