Solved

bash rsync script

Posted on 2011-02-13
5
968 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 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

Don't miss ATEN at NAB Show April 24-27!

Visit ATEN at NAB Show to learn how our "Seamlessly Entertaining" solutions deliver fast, precise video streaming without delays for the broadcasting and media environment. ATEN will showcase its 16x16 Modular Matrix Switch (VM1600) and KVM Over IP Solution (KE6900 series).

Question has a verified solution.

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

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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