|
|||||||||
| 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 |
| Tags |
| rsync |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
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} |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
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
|
||||
|
||||
|
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
|
||||
|
||||
|
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 ![]() |
| Sponsored Links | ||
|
|
![]() |
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 |
|
|