LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-03-2020, 04:35 PM   #1
opeth281
LQ Newbie
 
Registered: Oct 2018
Posts: 5

Rep: Reputation: Disabled
Rsync Script with cron and email notification


Hi to All,

The idea is to have a crontab in order to run a script that backs up my local files to my remote server. The problem is that if there are too many files to transfer (Example: I ripped a DVD in the last hour) the actual backup may take longer than 60 minutes. So I want to make script to check if my backup script, based on rsync, is running. I have managed to do that with flock. The quetion is that: When the Rsync starts, i want to send an email with all the names of the files that will be backup. If the connection lost during disconnections, i need to mail me which files has been transferred with success and not .If the rsync finished with success , then send an email that all the listed files have been sent with success. If the rsync has nothing to sent, don't sent an email.

Script:

Code:
rsync -av --append  --partial --bwlimit=64  --progress -e "ssh -p 22" root@19x.xxx.xxx.xxx:/mnt/To_Office/ /mnt/Office_files/
if [ "$?" -eq "0" ]
then
ssh -p 22 root@19x.xxx.xxx.xxx "rm -f /mnt/To_Office/*"
else
  echo "Error while transferring data "
fi
Crontab:

Code:
15 * * * *  /usr/bin/flock -n /root/scripts/To_Office.lck sh /root/scripts/To_Office.sh
Any help is much appreciated. Many thanks..

Last edited by opeth281; 04-03-2020 at 04:44 PM.
 
Old 04-03-2020, 11:56 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Check out rsnapshot...it uses rsync with a perl wrapper to manage multiple generations and frequencies, including the setup of cron jobs.
 
  


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
Email notification script failing to send when executed with cron pcarlso7 Linux - Software 2 10-24-2017 12:13 PM
Cron Email Notification - Perl Script jamesyreid Programming 3 07-21-2009 07:56 AM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
E-Mail notification to users via SMS (gateway script ok, but notification script?!?) Riku2015 Linux - Networking 10 03-08-2002 10:16 AM
Cron Email Notification(?) jamesyreid Linux - General 2 12-17-2001 10:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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