Crontab and Tar Backups
55 4 * * * tar -czvf backups/mud/main/swgi`date +%Y-%m-%d`.tgz swgi 2>&1 >> log/cron.log
4:55 comes and goes and the job never executes and nothing is written to the log file. I never tried adding any scripts to the cron directories in /etc, I suppose that would be the next step. Cron IS running:
root 1491 0.0 0.1 2048 892 ? Ss Feb08 0:00 /usr/sbin/cron
So I assume that perhaps I missed something? Any ideas?
4 Replies
@Shoie13:
I created a crontab using the crontab -e command, inserting:
55 4 * * * tar -czvf backups/mud/main/swgi`date +%Y-%m-%d`.tgz swgi 2>&1 >> log/cron.log
You are merging the stderr into the stdout then redirecting the stdout. This should be the other way around. i.e. command >>log/cron.log 2>&1
Maybe the output is getting mailed to you instead and you are never seeing it.
It would be a good idea to use full paths for 'swgi' and 'log/cron.log' too.
If this job really isn't running you should check /etc/cron.allow and /etc/cron.deny. See man crontab.
``
/bin/sh: -c: line 0: unexpected EOF while looking for matching
'
/bin/sh: -c: line 1: syntax error: unexpected end of file
````
What would that errror mean? The command runs fine when I use it.
As sednet says, it's usually a good idea to use explicit paths as well instead of relative paths.
@glg:
I've found it's better to write commands like that into a shell script. Test the shell script, make sure it works. Then call the shell script from cron.
That solved the problem and works beautifully. Much thanks.