LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 01-11-2012, 11:20 AM   #1
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Rep: Reputation: 49
notifications for rsync's done via crontab


I have some rsync commands scheduled in a crontab to backup data to another server. It's working great, but right now i'm manually checking folder sizes to see if they're match up for the most part since i don't really know what's happening when they run.

Does anyone have a suggestion as to how I could add something that emails me every time it runs saying like how much data the rsync added or deleted when it ran?

Guess i'm trying to simulate backup software that can email you a log of what each backup job did.
 
Old 01-11-2012, 11:23 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Are you doing this by a script or by a single line in your crontab? By default crond should e-mail you the results of anything it runs unless the output is being redirected. What's the line you have in your crontab?
 
Old 01-11-2012, 11:29 AM   #3
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
i dont have access to the server now, but in the crontab its just a rsync -options /path/ /path2/ type command
 
Old 01-11-2012, 11:41 AM   #4
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Check there's nothing like
Code:
> /dev/null
at the end, and also check to see if there's any
Code:
MAILTO=""
in the crontab above your line.
 
1 members found this post helpful.
Old 01-11-2012, 12:27 PM   #5
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
crond(8) mails stdout / stderr from each cronjob to the user it is running as. If that's root, then check his mail:
Code:
# mail
If you'd like the output to be mailed to a different user (even an external one), then utilize the crontab(5) MAILTO variable (mentioned above), or set up a mail alias.
 
Old 01-11-2012, 12:28 PM   #6
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
there is not a /dev/null or a MAILTO in the crontab for that user
 
Old 01-11-2012, 02:47 PM   #7
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
So add one.

Code:
MAILTO="foo@domain.local"
35 * * * * /cronjob/here
 
1 members found this post helpful.
Old 01-11-2012, 03:27 PM   #8
cbtshare
Member
 
Registered: Jul 2009
Posts: 645

Rep: Reputation: 42
you can use this ,I didnt know how your network is setup and where the backup server is, but since your rsyning I know you have at least key authentication, so it should be simple.Just use this script below.It will rsync your data as you always do, and present you with a log of what was done.It will then tell you whether or not both directories are the same in an email.

#!/bin/bash

PATH=/var/www
BACKUP=root@123.1.20.5:/usr/src
LOCALFOLDER=/var/www

COMMAND=$(rsync -options $PATH $BACKUP > ssh_log.txt.$(date + %F))


#WONT WORK
Quote:
SSH=$(ssh $BACKUP)
CHECK=$(diff $PATH $SSH)
#instead do the following


REMOTEFOLDER=$(ssh root@111.111.111.1 'ls -lA /var/www'| grep -E '^total' | cut -d " " -f 2 > remotessh.txt)

COMMAND=$(ls -lA $LOCALFOLDER | grep -E '^total' | cut -d " " -f 2 > localssh.txt)


REM=$(cat remotessh.txt)
LOCAL=$(cat localssh.txt)
#Or you can choose to diff the two files here.

if [ $REM -eq $LOCAL ]
then
echo Directories are the same
echo ssh_log.txt.$(date + %F) | mail -s "SSH LOGS"
else

echo Directories are differnt

fi

Last edited by cbtshare; 01-12-2012 at 10:17 AM.
 
1 members found this post helpful.
Old 01-11-2012, 03:57 PM   #9
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
Thanks. I'm not even sure how to tell if mail is setup, but at least i got some things to try out, see what works.
 
Old 01-11-2012, 04:44 PM   #10
cbtshare
Member
 
Registered: Jul 2009
Posts: 645

Rep: Reputation: 42
No prob, well I tested it out and this script is more efficient:It will do the same thing, tell you what has been done in rsync and then tell you if the directories are different.Mail command is just (mail -s "Rsync Logs" admin@mypplace.net)

#!/bin/bash

rsync -avz /var/www/* root@111.111.111.1:/hfs/ > ssh_log.txt

rsync -avz --dry-run /var/www/* root@111.111.111.1:/hfs/ >>ssh_log.txt


echo ssh_log.txt | mail -s "Rsync Logs" admin@mypplace.net
 
1 members found this post helpful.
Old 01-19-2012, 03:24 AM   #11
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
Sorry for the late reply. Thanks cbt. So which parts are key to add to my existing commands but in a .sh? obviously the last line that does the mail (once i figure out if mail is even setup or set it up myself), then just making sure my rsync's have verbose enabled and sending them to the text file?
 
  


Reply



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
[SOLVED] rsync execution issue with crontab - Have given full path to rsync too!! Prabagaran Linux - Server 6 04-15-2011 01:39 AM
rsync's in crontab not running, not sure why anon091 Linux - Newbie 47 07-17-2009 08:00 AM
Rsync and Crontab not playing well together phillc Linux - Newbie 9 11-08-2007 10:22 AM
Backup with rsync and crontab gjblackford Linux - General 4 01-04-2007 08:53 AM
rsync in crontab loonykroons Linux - Software 3 11-28-2006 03:08 AM

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

All times are GMT -5. The time now is 03:44 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