ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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...
if test -f /home/necrolin/.homebackup/snapshots/l0snapshot
# Copy snapshot files to avoid errors
cp /home/necrolin/.homebackup/snapshots/l0snapshot /home/necrolin/.homebackup/l1snapshot
# Run backup
tar -cvf /home/backup/level1.tar \
--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
echo "You must run a level 0 backup before you can run a level 1 backup"
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.
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. =)