Shell Script works different from cron
I wrote a simple shell script for backing up my home directory using the tar command. If I run the script from the command line then it backs up my files as required. Everything seems to work fine. However, when I run it from cron my results are different. It still creates a backup file however, all of the directories in the .tar file are empty. No actual files are backed up.
Here's the part of the script that actually does the backing up... l1backup() { if test -f /home/necrolin/.homebackup/snapshots/l0snapshot then # Copy snapshot files to avoid errors cp /home/necrolin/.homebackup/snapshots/l0snapshot /home/necrolin/.homebackup/l1snapshot # Run backup tar -cvf /home/backup/level1.tar \ --exclude=".*" \ --exclude="/home/necrolin/Videos" \ --exclude="/home/necrolin/Music" \ --exclude="/home/necrolin/examples.desktop" \ --label="Level 1 backup executed on: `date`" \ -g /home/necrolin/.homebackup/l1snapshot /home/necrolin # Copy snapshot file for use with level 2 backups cp /home/necrolin/.homebackup/l1snapshot /home/necrolin/.homebackup/snapshots/l1snapshot else echo "You must run a level 0 backup before you can run a level 1 backup" errorMsg fi } Any ideas? |
The environment (PATH etc) that is set from cron is quite different from the interactive login environment. Add "set -x" to the start of your script to see what the script is doing. The output will be emailed to you by cron, and feel free to post it if you need help deciphering it.
|
Solved
OK, I figured it out. It was so simple.... OMG.
The options I had were: tar -cvf. The -v (verbos) option would spit out all kinds of data which were useful for me in debugging the script. But, they happen to crash the cron job for some reason. Just remove the -v option and it works just fine. =) |
All times are GMT -5. The time now is 12:27 PM. |