From owner-freebsd-questions@FreeBSD.ORG Tue Dec 30 03:38:56 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1D70E106566B for ; Tue, 30 Dec 2008 03:38:56 +0000 (UTC) (envelope-from admin2@enabled.com) Received: from typhoon.enabled.com (typhoon.enabled.com [216.218.220.21]) by mx1.freebsd.org (Postfix) with ESMTP id 0AAB28FC0C for ; Tue, 30 Dec 2008 03:38:55 +0000 (UTC) (envelope-from admin2@enabled.com) Received: from [172.23.0.135] (nat-service4.juniper.net [66.129.225.151]) (authenticated bits=0) by typhoon.enabled.com (8.14.3/8.14.3) with ESMTP id mBU3ctQs035287 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 29 Dec 2008 19:38:55 -0800 (PST) (envelope-from admin2@enabled.com) Message-ID: <495997CA.9050708@enabled.com> Date: Mon, 29 Dec 2008 19:38:50 -0800 From: Noah User-Agent: Thunderbird 2.0.0.18 (Macintosh/20081105) MIME-Version: 1.0 To: Mel References: <4959509A.2060506@enabled.com> <200812291439.27877.fbsd.questions@rachie.is-a-geek.net> In-Reply-To: <200812291439.27877.fbsd.questions@rachie.is-a-geek.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-questions@freebsd.org Subject: Re: restart rsync process via shell script X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Dec 2008 03:38:56 -0000 Mel wrote: > On Monday 29 December 2008 13:35:06 Noah wrote: >> Hi there, >> >> I am trying to figure out the most accurate way to assess if an rsync >> process is running and is established to the remote rsync server and is >> transferring data. I am writing a bourne shell script to restart rsync >> if the connection to the remote rsync server is lost. >> >> The command "ps ax | grep 'rsync' | grep -v grep" is not enough because >> the rsync and ssh process can be running but the connection to the >> remote server is no longer ESTABLISHED and the backup is no longer >> proceeding. >> >> Then perhaps the command "netstat -A | grep '192.168.1.10' | grep >> 'ESTABLISHED' | grep -v grep" would be helpful. But in some cases I >> have found that I have ssh connections to the remote rsync server that >> obfuscate the rsync ssh ESTABLISH statistics. >> >> the rsync command I am using is: "/usr/bin/rsync -avz '/Users/noah/' -e >> 'ssh -p 22' root@192.168.1.10:/Users" >> >> Any suggestions please? > > Set ServerAliveInterval to a low value so the connection is dropped. You can > do this on the commandline using -e 'ssh -o ServerAliveInterval=10 -p 22'. > This would drop the connection if the server can't be reached within 10 > seconds. > Once the connection is dropped, rsync should exit with a value other then 0, > so you can wrap your rsync command in a while loop, like: > > KEEP_RUNNING=1 > while test ${KEEP_RUNNING} -gt 0; do > rsync -avz /Users/noah/ -e 'ssh -p 22 -o ServerAliveInterval=10' \ > root@192.168.1.10:/Users > KEEP_RUNNING=$? > done > I like that - thanks!