Solved

bash rsync script

Posted on 2011-02-13
5
965 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
  • 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 500 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now