homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

Help with simple shell script

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

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!




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

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)

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)

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?

brotherhood of LAN

 4:48 pm on Feb 28, 2014 (gmt 0)

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

Global Options:
 top home search open messages active posts  

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved