?
Solved

bash rsync script

Posted on 2011-02-13
5
Medium Priority
?
980 Views
Last Modified: 2012-05-11
I have the following bash script which kicks off every hour via  cron job.  My remote server drops the connection every now and again that is why I run it every hour.  I have a line that checks for the process, if the process exists it does start a new one, if the process does not exist it runs the rsync job again and starts off where it left off.

The problem I am having is that even when the remote server drops the connection the script just hangs and still shows as a running process.

Any help?


#!/bin/bash
# Check for rsync running under my username
TODAY=`date +%m-%d-%y`
RUNLOG=/home/user/scripts/rsync.log.$TODAY
SERVICE='rsync'

if ps ax | grep -v grep | grep user | grep $SERVICE > /dev/null

then
        echo "The process exists..." >> $RUNLOG
else
        # Run rsync command
        echo "Starting rsync..." >> $RUNLOG
        rsync -aP --update --bwlimit=300 -e 'ssh -p 2222' /vault/ user@remote.com:/home/user/vault >> $RUNLOG
fi

Open in new window

0
Comment
Question by:savone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:de2Zotjes
ID: 34883733
You are using ssh as the transport mechanism. If you somehow disabled serveralive detection in ssh the script will indeed sit idle forever if the connection is interrupted.

So make sure the ServerAlive settings for ssh are proper, that way the script will end.
0
 
LVL 10

Expert Comment

by:APNFSSC
ID: 34884887
Hi,

You could try adding the --timeout option to your rsync to see if it catches the hung process and terminates it?

Cheers
0
 
LVL 23

Author Comment

by:savone
ID: 34884996
@APNFSSC - Can you give me a little more info on how the timeout option works?

I see the man page says:
set IO timeout in seconds

But what exactly does that mean?  Does it timeout after no IO for a specified amount of seconds?

0
 
LVL 10

Accepted Solution

by:
APNFSSC earned 2000 total points
ID: 34885014
Hi,

--timeout=TIMEOUT
    This option allows you to set a maximum IO timeout in seconds. If no data is transferred for the specified time then rsync will exit. The default is 0, which means no timeout.

Your exactly correct if no IO for x number of seconds then process will exit.

You just need to balance the timeout with the length of time it usually takes to run and your interval for running the job.
0
 
LVL 23

Author Closing Comment

by:savone
ID: 34888244
That seems to have done the trick.  The connection dropped out and I had --timeout=360 (six minutes).  The session timed out and killed the script.  Thanks
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question