Rsync script in cron from stepping on itself


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Rsync script in cron from stepping on itself
# 1  
Old 04-29-2008
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 Smilie

# 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}
sunsysadm2003
# 2  
Old 04-29-2008
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  
Old 04-29-2008
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 04-30-2008
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 Smilie
sunsysadm2003
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Email Notifications on Cron Bash Error Only cp mv rsync

Wondering if anyone can point me to an example of how to setup a bash script that executes cp mv and rsync commands and only sends an email if there were errors with any of those commands and what the errors are. In addition it should email if the cron event to execute the script fails, or in... (1 Reply)
Discussion started by: consultant
1 Replies

2. UNIX and Linux Applications

Rsync works in shell but not in cron

So I have this rsync script I wrote to grab some sql files and import them to a database. I left in the mysql stuff just give context to the situation. The real problem is with my rsync code. script.sh (chmod 744) #!/bin/sh rsync -av --rsh="sshpass -p'PASSWORD' ssh -l'USERNAME'"... (3 Replies)
Discussion started by: noPermissions
3 Replies

3. Solaris

stepping through newfs

On a RAID-5 solaris 9 server, we replaced a bad disk. Upon boot up, a mount point failed: vxvm:vxvol: ERROR: Volume IQ_Staging is not startable; some subdisks are unusable and the parity is stale With Sun tech support, we tried vxvol start and vxvol resync, but it remained... (3 Replies)
Discussion started by: abstractrick
3 Replies

4. UNIX for Dummies Questions & Answers

Problems using rsync with cron

Hi, I've created a cron job for a script with a rsync command in it. The script is named pull.sh and contains the following line : What it is supposed to do is pull backup files from the production server of my company to my local server. It should also generate the log file (output.log)... (1 Reply)
Discussion started by: anaigini45
1 Replies

5. Linux

Stair stepping

Is there a command line flag to lpr or a utility similar to the Unix 'xtod' command to fix stair stepping when printing? Under Unix I would: # cat textfile | xtod | lp -d lineprinter Anything like that for linux? Thanks (1 Reply)
Discussion started by: lochraven
1 Replies

6. UNIX for Advanced & Expert Users

rsync not working thro' cron

Hi, I am able to use rsync and run it thro' command line. But when I schedule a script file that has rsync command thro' cron, the job doesn't get executed. All other jobs in the cron runs fine. cron entry-- 57 13 * * * /home/apm/cron/rsync-backup.sh rsync-backup.sh file-- rsync -avz... (1 Reply)
Discussion started by: sm23328
1 Replies

7. UNIX for Dummies Questions & Answers

rsync not working thro' cron -RH Linux

Hi, I am able to use rsync and run it thro' command line. But when I schedule a script file that has rsync command thro' cron, the job doesn't get executed. All other jobs in the cron runs fine. cron entry-- 57 13 * * * /home/apm/cron/rsync-backup.sh rsync-backup.sh file-- rsync -avz... (1 Reply)
Discussion started by: sm23328
1 Replies

8. UNIX for Advanced & Expert Users

Rsync via cron

Hi, I am running a rsync via cron job. Its running fine and is scheduled to 9:00 AM everyday. Sometimes it runs for more than 24 hours, such that the next days cron also fires. Now how will the sync happen as the <sync file> that both crons have created might conflict. Thanks (5 Replies)
Discussion started by: vibhor_agarwali
5 Replies

9. UNIX for Dummies Questions & Answers

use rsync by cron

Hi there: I run rsync very well by typing: rsync -avz /source /destination Then I want to run it by cron. So I had a crontab file like this: * * * * * rm file * * * * * rsync -avz /source /destination > cron_result (The first line is used to test whether cron is working.) When I check... (0 Replies)
Discussion started by: Steven.surfboy
0 Replies

10. UNIX for Dummies Questions & Answers

stepping through ascii file

How can one step through an ascii file line by line looking for a word and then pull out the whole section that the word is in. I have a project working Oracles tkprof utility where I am trying to look for a word and need to pull out the section of the ascii file that the word is in. I have not... (12 Replies)
Discussion started by: rehoboth
12 Replies
Login or Register to Ask a Question