The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Rsync via cron vibhor_agarwali UNIX for Advanced & Expert Users 5 07-03-2007 07:23 AM
Scripting stepping stones. syndex UNIX for Dummies Questions & Answers 2 07-02-2007 11:53 AM
use rsync by cron Steven.surfboy UNIX for Dummies Questions & Answers 0 02-20-2006 05:19 PM
Cron Script Q doublek321 Shell Programming and Scripting 2 07-06-2004 10:35 PM
stepping through ascii file rehoboth UNIX for Dummies Questions & Answers 12 08-30-2002 01:06 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-29-2008
sunsysadm2003
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
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

# 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}
  #2 (permalink)  
Old 04-29-2008
in2nix4life's Avatar
in2nix4life in2nix4life is offline
Registered User
  
 

Join Date: Oct 2007
Location: East Coast
Posts: 58
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.
  #3 (permalink)  
Old 04-29-2008
reborg's Avatar
reborg reborg is online now Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,246
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 (permalink)  
Old 04-30-2008
sunsysadm2003
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0