Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

learn linux and unix commands - unix shell scripting

Rsync script in cron from stepping on itself

Shell Programming and Scripting


Tags
rsync

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 04-29-2008   -   Original Discussion by sunsysadm2003
sunsysadm2003's Unix or Linux Image
sunsysadm2003
Guest
 
Posts: n/a
Rsync script in cron from stepping on itself

I have the following rsync script that I use for syncing MySQL files from one server to another. I run the script at 20 minutes past every second hour in cron. I want to make sure that the script completes in it's entirety before it is set to kick off again. For example, when the script starts at 1:20pm, it should finish before the 3:20pm interation of the script. If the 1:20pm script is still running, I would want the 3:20pm interation of the script to not run and maybe even send me an email. Below is the script I have as it currently runs. Any help, suggestions would be appreciated Linux

# Variables
#
REMHOST="serverB"
ERRFILE="/tmp/rsync_mysql_error.log"
MAIL_LIST="System.Administrator@mydomain.com"

# Following options equate to: preserve links,recursive,preserve permissions,
# preserve times,quiet,and compress

OPTS="-lrptqz"

#NOTE: You must put a slash (/) at the end of your paths for the dirs to copy correctly!

/usr/local/bin/rsync $OPTS /apps/mysql/data/var/ $REMHOST:/apps/mysql/data/var/ > ${ERRFILE}

if [ -s ${ERRFILE} ]; then
mailx -s "/apps/mysql/mysql_rsync.ksh script encountered an error...Please investigate." ${MAIL_LIST} < ${ERRFILE}
fi
rm ${ERRFILE}
Sponsored Links
    #2  
Old Unix and Linux 04-29-2008   -   Original Discussion by sunsysadm2003
in2nix4life's Unix or Linux Image
in2nix4life in2nix4life is offline
Registered User
 
Join Date: Oct 2007
Last Activity: 9 October 2016, 12:41 PM EDT
Location: East Coast
Posts: 621
Thanks: 1
Thanked 177 Times in 163 Posts
Maybe at the beginning of the script you could record the PID of the script and save it to a file. Then use an if..then statement to check for the presence of this file containing the PID. If it exists then send the email, else continue on with the script:

pid=`echo $$`
echo $pid > /tmp/${0##*/}.pid

if [ -e /tmp/${0##*/}.pid ]
then
mailx ....
fi

Then at the end of the script, remove the PID file which would signify that the script completed it's run.

rm -f /tmp/${0##*/}.pid

Hope this helps point you in the right direction.
Sponsored Links
    #3  
Old Unix and Linux 04-29-2008   -   Original Discussion by sunsysadm2003
reborg's Unix or Linux Image
reborg reborg is offline Forum Advisor  
Administrator Emeritus
 
Join Date: Mar 2005
Last Activity: 29 March 2012, 7:00 PM EDT
Location: Ireland
Posts: 4,464
Thanks: 0
Thanked 14 Times in 12 Posts
Are you doing this to replicate a mysql database? Judging by the script that is the case, and you could probably achieve this far more effectively by using the master/slave replication of mysql directly.
    #4  
Old Unix and Linux 04-30-2008   -   Original Discussion by sunsysadm2003
sunsysadm2003's Unix or Linux Image
sunsysadm2003
Guest
 
Posts: n/a
Thanks for the tip in2nix4life...that is exactly what I was looking for. I plan on test driving that today !

As to your question reborg, we are doing the rsync as a "poorman's" failover solution. I asked our DBA about the replication you mentioned and he stated that they had tested it before and had encountered some sort of network related issues, etc. and did not want to use that.

Thanks again for all the help and suggestions, this is a wonderful site for learning and sharing technical knowledge Linux
Sponsored Links
Closed


Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Rsync works in shell but not in cron noPermissions UNIX and Linux Applications 3 11-23-2011 04:16 PM
Problems using rsync with cron anaigini45 UNIX for Dummies Questions & Answers 1 12-15-2009 02:50 AM
rsync not working thro' cron sm23328 UNIX for Advanced & Expert Users 1 06-20-2008 01:13 PM
Rsync via cron vibhor_agarwali UNIX for Advanced & Expert Users 5 07-03-2007 07:23 AM
use rsync by cron Steven.surfboy UNIX for Dummies Questions & Answers 0 02-20-2006 05:19 PM



All times are GMT -4. The time now is 12:06 AM.