I am very new to UNIX as well as scripting so please be gentle, haha.
I have a Linux client which has a mount point mapped to my /etc folder on a NetApp FAS system. I woudl like to be able to copy the hosts and rc files once a week from the FAS to a different location for backup.
When the copy happens I would like the script to create a folder based on the current date, then copy the rc and hosts file to that new folder. Once this copy is successful I would like a basic email to be sent to a DL to inform everyone that the copy succeeded.
You can use the cp command to do the copying, the return value of the previous command is $? so yu can test for success by checking that value, the sendmail binary can be used to send a mail from the command line with the -t flag (this may need adaption depending onb your site setup), and the whole lot can be scheduled with cron .
So far this is what i have for the copying process at least:
mkdir /mnt/backup/$(date +%F)
#(create dated folder on destination [linux VM])
cp /mnt/FAS/etc/hosts /mnt/backup/$(date +%F)
#(copy from my Netapp to the local VM file structure)
So i guess this is where im stuck. How can i validate that this copy was in fact successful? I would like to get an email with a "Success" or "Failure" and the name of the NetApp (as there will be many that this will be run separately on) So if for some reason NetApp15 failed during the copy, we will be informed and will be able to investigate the issue.
success=1
if [ ! -d /mnt/backup/$(date +%F) ]
then
mkdir /mnt/backup/$(date +%F) || success=0
#(create dated folder on destination [linux VM])
fi
if [ $success = 1 ]
then
cp /mnt/FAS/etc/hosts /mnt/backup/$(date +%F) || success=0
#(copy from my Netapp to the local VM file structure)
fi
if [ $success = 1 ]
then
echo "copy success" | mailx -s "File copy success" minnino@minnino.server.com
else
echo "copy failed" | mailx -s "File copy failed" minnino@minnino.server.com
fi
Thanks rdrtx1, i ran that script and got the following output. The only thing i changed at all was the paths, and did an 'echo' in front of each line so i could see it run...