From owner-freebsd-questions@FreeBSD.ORG Mon Dec 29 23:39:29 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 660A8106566C for ; Mon, 29 Dec 2008 23:39:29 +0000 (UTC) (envelope-from fbsd.questions@rachie.is-a-geek.net) Received: from mail.rachie.is-a-geek.net (rachie.is-a-geek.net [66.230.99.27]) by mx1.freebsd.org (Postfix) with ESMTP id 2FAD18FC08 for ; Mon, 29 Dec 2008 23:39:28 +0000 (UTC) (envelope-from fbsd.questions@rachie.is-a-geek.net) Received: from localhost (mail.rachie.is-a-geek.net [192.168.2.101]) by mail.rachie.is-a-geek.net (Postfix) with ESMTP id 17F09AFBC02; Mon, 29 Dec 2008 14:39:28 -0900 (AKST) From: Mel To: freebsd-questions@freebsd.org Date: Mon, 29 Dec 2008 14:39:27 -0900 User-Agent: KMail/1.9.10 References: <4959509A.2060506@enabled.com> In-Reply-To: <4959509A.2060506@enabled.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200812291439.27877.fbsd.questions@rachie.is-a-geek.net> Cc: Noah 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: Mon, 29 Dec 2008 23:39:29 -0000 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 -- Mel Problem with today's modular software: they start with the modules and never get to the software part.