LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-06-2009, 07:53 PM   #1
necrolin
LQ Newbie
 
Registered: Jun 2003
Posts: 10

Rep: Reputation: 0
Question 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?

Last edited by necrolin; 05-06-2009 at 07:55 PM.
 
Old 05-06-2009, 10:18 PM   #2
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 4&5, Fedora 10, CentOS 5.4, IPCop
Posts: 569

Rep: Reputation: 54
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.
 
Old 05-07-2009, 09:52 AM   #3
necrolin
LQ Newbie
 
Registered: Jun 2003
Posts: 10

Original Poster
Rep: Reputation: 0
Smile 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. =)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell prompt works, cron job fails btuley Linux - General 1 11-13-2008 11:40 AM
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
Script works when run manually but not in cron job Harlin Linux - Software 7 10-16-2007 06:36 PM
Command works in shell, fails as a cron task angeljusto Linux - Software 3 06-13-2007 07:06 AM
command works in shell, but not in cron bret Linux - Newbie 10 09-04-2006 02:16 AM


All times are GMT -5. The time now is 07:33 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration