[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

bash rsync script

Posted on 2011-02-13
5
Medium Priority
?
986 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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)
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

649 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