Results 1 to 9 of 9
hello all,
Currently I have a backup script which every night will write to a tape, and store the tape output to a log file.
In the same script it ...
- 01-13-2009 #1Just Joined!
- Join Date
- Jan 2007
- Posts
- 38
backup script
hello all,
Currently I have a backup script which every night will write to a tape, and store the tape output to a log file.
In the same script it will then email out the log file to email address i specify.
However, also have (If any errors are encountered) that it writes these errors to a 'error log' file.
However, the problem I have is that when the backup fails - i.e no tape, it just emails a blank email (Which would of been the log file), is there anyway I can email error file (in the same email) or even better would be that if the backup failed, instead of using the log file it emails the error file.
Please see below for my current syntax (minus the variables):
rm /utils/tar.all.log
rm /utils/tar.all.error.log
cd $STARTDIR
tar cvf $TAPEDEVICE $DATESTAMP * 2>$TAPEERRORLOGFILE > $TAPELOGFILE
echo "Backup of X Server $STARTDIR finished" $NOW >> $DATESTAMP
tar tvf $TAPEDEVICE |mail -s "System backup of X Server $(date)" -c $C
USTOMEREMAIL $CUSTOMEREMAIL2 $MAIL
tar tvf $TAPEDEVICE >> $TAPELOGFILE
- 01-13-2009 #2Linux User
- Join Date
- Jun 2007
- Posts
- 318
Check the return status after tar runs. If it's zero, the backup worked. If it's non-zero, then it (probably) failed.
Code:tar cvf $TAPEDEVICE $DATESTAMP * 2>$TAPEERRORLOGFILE > $TAPELOGFILE if [ $? = 0 ] then mail_log_file else mail_error_file fi
- 01-13-2009 #3Just Joined!
- Join Date
- Jan 2007
- Posts
- 38
Thanks for your help.
This is how it looks at the moment, but i havent ran it yet as I am working remotely.
rm /utils/tar.all.log
rm /utils/tar.all.error.log
cd $STARTDIR
tar cvf $TAPEDEVICE $DATESTAMP * 2>$TAPEERRORLOGFILE > $TAPELOGFILE
if[$? =0]
mail -s "System backup of $CUSTOMER completed $(date)" -c $CUSTOMEREMAIL1 $CUSTOMEREMAIL2 $EMAIL >$TAPELOGFILE
else
mail -s "System backup of $CUSTOMER completed $(date)" -c $CUSTOMEREMAIL1 $CUSTOMEREMAIL2 $EMAIL > $TAPEERRORLOGFILE
fi
- 01-14-2009 #4Linux User
- Join Date
- Jun 2007
- Posts
- 318
bash is a bit touchy when it comes to spaces so:
won't work. This will:Code:if[$? =0]
You also forgot the 'then' before the 1st mail.Code:if [ $? = 0 ]
- 01-14-2009 #5Just Joined!
- Join Date
- Jan 2007
- Posts
- 38
Thanks, I noticed that after uploading it onto the forums!
rm /utils/tar.all.log
rm /utils/tar.all.error.log
cd $STARTDIR
tar cvf $TAPEDEVICE $DATESTAMP * 2>$TAPEERRORLOGFILE > $TAPELOGFILE
if [ $? = 0 ]
then
mail -s "System backup of $CUSTOMER completed $(date)" -c $CUSTOMEREMAIL1 $CUSTOMEREMAIL2 $VALEEMAIL >$TAPELOGFILE
else
mail -s "System backup of $CUSTOMER Failed $(date)" -c $CUSTOMEREMAIL1 $CUSTOMEREMAIL2 $VALEEMAIL > $TAPEERRORLOGFILE
fi
This is how it looks now, but when I run it I get a problem with the mail command saying it is expecting:
mail: option requires argument --c
- 01-14-2009 #6Linux User
- Join Date
- Jun 2007
- Posts
- 318
One thing I see is your directing output from mail to the log files, not specifying the files as input. The '>' when it should be '<'.
Code:if [ $? = 0 ] then mail -s "System backup of $CUSTOMER completed $(date)" -c $CUSTOMEREMAIL1 $CUSTOMEREMAIL2 $VALEEMAIL < $TAPELOGFILE else mail -s "System backup of $CUSTOMER Failed $(date)" -c $CUSTOMEREMAIL1 $CUSTOMEREMAIL2 $VALEEMAIL < $TAPEERRORLOGFILE fi
- 01-14-2009 #7Just Joined!
- Join Date
- Jan 2007
- Posts
- 38
thanks for pointing that out, but it still does the same error:
[root@centos utils]# ./diskspacecheck
mail: option requires an argument -- c
Usage: mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...
[- sendmail-options ...]
mail [-iInNv] -f [name]
mail [-iInNv] [-u user]
[root@centos utils]#
- 01-14-2009 #8Linux User
- Join Date
- Jun 2007
- Posts
- 318
OK, didn't look too closely at the error message. Sounds like variables CUSTOMEREMAIL1, CUSTOMEREMAIL2, VALEEMAIL, aren't defined. You can see what the actual mail command looks like by running the script like this:
Code:sh -vx ./diskspacecheck
- 01-14-2009 #9Just Joined!
- Join Date
- Jan 2007
- Posts
- 38
Thanks that worked brilliantly

You were correct, it wasn't setting the variable for one of the email addresses. Doh!


Reply With Quote
