I'm a newbie to scripting/programming and have a question on a simple backup script.
Basically, all this script does is tar a bunch of config files into a single tarball and then email root on whether or not it backed up all of the files. My problem is that it says it runs successfully everytime, even if I remove one of the files so that it can't back it up. It looks something like this...
#!/bin/bash
# Create a file with todays date inside
echo `date` > /home/linux_backups/date.txt
# Remove the old tar archive
rm -f /home/linux_backups/backup.tar
# Tar it up, while retaining permissions...
tar cpvf /home/linux_backups/backup.tar /home/linux_backups/date.txt /file1 /file2
# Change the permissions on the backup folder so that only root can access it
chmod -R 700 /home/linux_backups/
chown -R root.root /home/linux_backups/
# Did the script execute successfully?
echo $?
if [ `echo $?` = 0 ]
then
echo "The backup script on Voyager completed successfully" | mail root
else
echo "The backup script on Voyager failed" | mail root
fi
Thanks,
Chris
Basically, all this script does is tar a bunch of config files into a single tarball and then email root on whether or not it backed up all of the files. My problem is that it says it runs successfully everytime, even if I remove one of the files so that it can't back it up. It looks something like this...
#!/bin/bash
# Create a file with todays date inside
echo `date` > /home/linux_backups/date.txt
# Remove the old tar archive
rm -f /home/linux_backups/backup.tar
# Tar it up, while retaining permissions...
tar cpvf /home/linux_backups/backup.tar /home/linux_backups/date.txt /file1 /file2
# Change the permissions on the backup folder so that only root can access it
chmod -R 700 /home/linux_backups/
chown -R root.root /home/linux_backups/
# Did the script execute successfully?
echo $?
if [ `echo $?` = 0 ]
then
echo "The backup script on Voyager completed successfully" | mail root
else
echo "The backup script on Voyager failed" | mail root
fi
Thanks,
Chris