Welcome to WebmasterWorld Guest from 184.73.126.70

Forum Moderators: bakedjake

Message Too Old, No Replies

Help with simple shell script

   
3:33 pm on Feb 26, 2014 (gmt 0)

5+ Year Member



Hi all - looking for someone to help with my shell script. I want the script below to email verbose results. And in the event of an error, put that in the subject line of the email (and put error details in the body?).

rm -rf /backups/sunday_week_prior/*
cp -rf /backups/sunday_am/* /backups/sunday_week_prior/

mysqldump -uuser -ppass database1 | gzip -9 > /backups/sunday_am/database1.sql.gz
mysqldump -uuser -ppass database2 | gzip -9 > /backups/sunday_am/database2.sql.gz
mysqldump -uuser -ppass database3 | gzip -9 > /backups/sunday_am/database3.sql.gz
mysqldump -uuser -ppass database4 | gzip -9 > /backups/sunday_am/database4.sql.gz

/usr/local/bin/rsync --del -vrplogDtH /backups/ root@mywebsite:/backups/

echo "Rsync backup has completed." | mail -s "WEEKLY MYSQLDUMP & RSYNC IS COMPLETE" myemail@gmail.com


Thank you for your help!

Addict
8:29 pm on Feb 27, 2014 (gmt 0)

WebmasterWorld Senior Member dstiles is a WebmasterWorld Top Contributor of All Time 5+ Year Member



I'm not familiar with the actual process you propose but for mailing I would look into sendemail (note the E in the middle of that!).

I use sendemail for quite a few scripted and other apps (luckybackup, urlwatch etc). Quite versatile, allows proper FQDN and so on to get over anti-spam setups, and has syntax for sending files as the message body.

Would I be correct in reading from your script that the fact the backup has completed is no guarantee that any backup has actually occurred? There seems to be no error trapping, is my point.

In passing, I backup my own MySQL databases (mainly windows) from within the admin or workbench software.
8:33 pm on Feb 27, 2014 (gmt 0)

5+ Year Member



correct - in the script there is no error trapping. I can see it in the verbose results if I just execute the rsync from the command line, but I am using cron to run this script - so when it is done executing it sends me an email - which works - I just need it to display if any errors occured, OR just port the verbose to the email body. I just don't know how to do it.
4:38 pm on Feb 28, 2014 (gmt 0)

5+ Year Member



Not many script writers in here, huh? Should I be posting this in another forum? Or does someone know a different website that might be the appropriate place to be asking this type of question?
4:48 pm on Feb 28, 2014 (gmt 0)

WebmasterWorld Administrator brotherhood_of_lan is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Try redirecting STDERR to STDOUT by adding " 2>&1" after any command line args to your script.