LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-25-2010, 11:50 AM   #1
fruitwerks
Member
 
Registered: Apr 2009
Posts: 77

Rep: Reputation: 15
Tweaking an rsync script - need a few extras


I have a script that runs my daily rsync, I would like to expand it to email the output, and on a fail, an alternate email address. Also I would like to have the seconds converted to HH:MM:SS if it's not a big deal.

What I have so far is the extent of my abilities.
Thanks!

Code:
start=$SECONDS;
if rsync_output=$(rsync ...
then echo Success;
else echo Fail;
fi;
echo "$rsync_output"
echo time in seconds =$((SECONDS-start))
 
Old 06-26-2010, 02:15 AM   #2
Jerre Cope
Member
 
Registered: Oct 2003
Location: Texas (central)
Distribution: ubuntu,Slackware,knoppix
Posts: 323

Rep: Reputation: 37
Here's some code to start you.

Code:
#backup
RSERR=/home/logs/rserr.log
SUCCESSLOG="/home/logs/rs_success"
BSERVER="backupserver"
export RSERR BSTATUS SUCCESSLOG BSERVER

ping -q -c1 $BSERVER >/dev/null || exit

>$RSERR
echo " " >>$SUCCESSLOG
echo "rsync to $BSERVER" >$SUCCESSLOG
echo "Started `date`" >>$SUCCESSLOG
echo " " >>$SUCCESSLOG

rsync --recursive -azv /blah/blah/ "$BSERVER":/blah/blah 2>>$RSERR >>$SUCCESSLOG

if [ -s $RSERR ]
then
        mailpager.pl "myself@example.com" $RSERR "Rsync Report"
        mailpager.pl "someoneelse@example.com" $RSERR "Rsync Report"
        exit
fi

echo "Finished ok `date`" >>$SUCCESSLOG
mailpager.pl "myself@example.com" $SUCCESSLOG "Rsync Report $BSERVER"
mailpager.pl "someoneesle@example.com" $SUCCESSLOG "Rsync Report $BSERVER"
I use a Perl script to send mail out authenticated since I'm sending from a NATted private IP. You'll probably want to use the Net::SMTP; in Perl to accomplish the same if you are behind a firewall.

Perl has all kinds of good tools to convert localtime. Really, you/I might consider rewriting the whole script in Perl. Just download the Perldocs to a local file, point your browser to it, and stay camped out in the Overview section for a while...

Have fun!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Question on rsync script, not doing what it should be doing... JockVSJock Programming 5 01-03-2010 03:07 PM
Rsync script for the first patches of Slackware 11 Alien Bob Slackware 4 10-26-2006 02:06 PM
rsync script twantrd Programming 2 01-06-2005 06:46 AM
bash script HELP - dnotify > rsync GuitsBoy Programming 5 01-28-2004 10:42 AM
Backup Script Tweaking and Debugging KungFuHamster Programming 1 12-07-2003 03:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration