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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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. =)