Solved

bash rsync script

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
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 several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

744 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

9 Experts available now in Live!

Get 1:1 Help Now