Results 1 to 6 of 6
Alright, I have this script, and it works pretty well if I execute it from the terminal. However, it seems that cron has an inability to correctly carry out the ...
- 12-05-2007 #1
Why doesn't my backup script work with cron?
Alright, I have this script, and it works pretty well if I execute it from the terminal. However, it seems that cron has an inability to correctly carry out the tasks.
To say the least, I don't really see any different between what cron and I are doing.
Maybe one of you can figure it out:
details:
1. the cronfile is called "cronfile"
2. it's located inside of the user's home folder: $HOME/.cronjobs/
3. I installed the cronfile from rc.local
4. The part I'm concerned with is in red
Code:#!/bin/sh crontab -u workstation /home/workstation/.cronjobs/cronfile
Not too much of a big deal.Code:# # This is the crontab for $HOME/ # ########################################################################## # Update the background wallpaper every _1_ minutes */1 * * * * bash $HOME/.GUI/random-background.sh ########################################################################## # ########################################################################## # # openoffice.org backups # */5 * * * * bash $HOME/.cronjobs/backups/ooo_backups.sh ########################################################################## # ########################################################################## # openoffice.org file collection # */20 * * * * bash $HOME/.cronjobs/backups/ooo_filecollect.sh ########################################################################## # ########################################################################## # AbiWord file collection */5 0-23 * * * bash $HOME/.cronjobs/backups/abw_filecollect.sh ##########################################################################
Now, every five minutes, the script does execute. But it seems to give me a file with the extension ".tar"; it doesn't seem to give me that archived file itself.
Here is abw_filecollect.sh
So, that's that.Code:#!/bin/sh # # This script collects scattered abiword.org documents and archives them # # Change the 5 variables below to fit your computer/backup # # # create the archive folders mkdir $HOME/archives/ mkdir $HOME/archives/abiword/ # Collect files mkdir /home/workstation/abiword/ mkdir /home/workstation/abiword/Desktop/ # copy from /home cp /home/workstation/*.abw /home/workstation/abiword/ cp /home/workstation/*.awt /home/workstation/abiword/ cp /home/workstation/*.doc /home/workstation/abiword/ cp /home/workstation/*.rtf /home/workstation/abiword/ cp /home/workstation/*.txt /home/workstation/abiword/ cp /home/workstation/*.bak~ /home/workstation/abiword/ # copy from ./Desktop cp /home/workstation/Desktop/*.abw /home/workstation/abiword/Desktop/ cp /home/workstation/Desktop/*.awt /home/workstation/abiword/Desktop/ cp /home/workstation/Desktop/*.doc /home/workstation/abiword/Desktop/ cp /home/workstation/Desktop/*.rtf /home/workstation/abiword/Desktop/ cp /home/workstation/Desktop/*.txt /home/workstation/abiword/Desktop/ cp /home/workstation/Desktop/*.bak~ /home/workstation/abiword/Desktop/ COMPUTER=workstation # name of this computer DIRECTORIES="/home/workstation/abiword/" # directories to backup BACKUPDIR=$HOME/archives/abiword # where to store the backups TAR=/bin/tar # name and locaction of tar #You should not have to change anything below here PATH=/usr/local/bin:/usr/bin:/bin DM=`date +%m-%d-%Y@"("%H.%M.%S")"` # mm/dd/yy@HH:MM e.g. 07-04-2005@(07.14.03) # Backup the moment $TAR -cf $BACKUPDIR/$DM-$COMPUTER.tar $DIRECTORIES # Remove used materials rm -r /home/workstation/abiword/
Cron doesn't seem to actually make an archive file; it makes a file with the extension ".tar"; each time, the file is like 0 bytes. I don't know what is up with that.

The last file was executed by terminal.
The others were done by cron.
But, if I execute it from the terminal while logged in as the user "workstation," then it actually creates the archived ".tar" of whatever abiword files might be around.
I don't know why it's not working.
Any guesses?
- 12-05-2007 #2Linux User
- Join Date
- Jun 2007
- Posts
- 318
Need more information. I suggest you do the following:
Enable verify mode by appending -vx to the 1st line of your script:
Change your crontab to pipe all output to a log file:Code:#!/bin/sh -vx
Then look at the log for errors or post the log.Code:*/5 0-23 * * * bash $HOME/.cronjobs/backups/abw_filecollect.sh > $HOME/abw_filecollect.log 2>&1
- 12-05-2007 #3
I believe it has to do with the rc.local file.
Rc.local runs as root during bootup.
WHile in terminal, I was the user, not root.
I assume that's the problem, because when I reloaded the cronfile as the user, it executed correctly.
So, anyway I can fix this problem, or should I make it a startup program in gnome?
- 12-05-2007 #4Linux Guru
- Join Date
- Nov 2004
- Posts
- 6,110
I assume you are not leaving the $HOME variable as a variable in the cron script?
- 12-06-2007 #5Linux Enthusiast
- Join Date
- Aug 2006
- Location
- Portsmouth, UK
- Posts
- 539
As bigtom says, $HOME is a no no.
I'm not sure if ~ will work, I usually give the full path to scripts in cron.RHCE #100-015-395
Please don't PM me with questions as no reply may offend, that's what the forums are for.
- 12-08-2007 #6Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044


Reply With Quote

