From owner-freebsd-questions@FreeBSD.ORG Wed Apr 6 23:43:16 2011 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 6F071106564A for ; Wed, 6 Apr 2011 23:43:16 +0000 (UTC) (envelope-from yuri.pankov@gmail.com) Received: from mail-bw0-f54.google.com (mail-bw0-f54.google.com [209.85.214.54]) by mx1.freebsd.org (Postfix) with ESMTP id E91AF8FC13 for ; Wed, 6 Apr 2011 23:43:15 +0000 (UTC) Received: by bwz12 with SMTP id 12so2005578bwz.13 for ; Wed, 06 Apr 2011 16:43:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:x-authentication-warning:date:from:to:cc :subject:message-id:references:mime-version:content-type :content-disposition:in-reply-to:user-agent; bh=Z4PKzQV5HH7ry1/Lo/nqWTI0jRiRFY8GTmZMe709Fyw=; b=ub5HK0O1SucZUooyir8C1nH4LNeiFAH/QqZsCCYNhyd7I4mqFKZT+XZ97P0jfGHzbi 6Tp6yPmjh1rclaeml3x+QpzzZ3YS0CBWL+VzR9uGjBL9CAAzE/B02gDpRQ4Y2qRdYDJR qj2/jgPhAyAbkQD2x5qSivmKRrjbLl3kJCHxQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=x-authentication-warning:date:from:to:cc:subject:message-id :references:mime-version:content-type:content-disposition :in-reply-to:user-agent; b=PHzKxOFFmhp2Cmhz/Zp1q1Alg6MN+IUzj4P4URISSLbfFgziK0OazSOxHSlaRJvLlE BpWvVBUq0vJn9/DRGsmnc16Q97PNrLS4Taw6cZFDby3DSy7+xu3qSd0IO9gDxHeyaoiE /EAYvJqbcw3cFkIMxMizNSAAjWtxsdV1ycSj0= Received: by 10.204.81.27 with SMTP id v27mr157065bkk.115.1302132053869; Wed, 06 Apr 2011 16:20:53 -0700 (PDT) Received: from darklight.org.ru ([213.132.76.142]) by mx.google.com with ESMTPS id q18sm701910bka.3.2011.04.06.16.20.52 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 06 Apr 2011 16:20:53 -0700 (PDT) Received: from darklight.org.ru (yuri@darklight.org.ru [IPv6:::1]) by darklight.org.ru (8.14.4/8.14.4) with ESMTP id p36NKoh1014569; Thu, 7 Apr 2011 03:20:50 +0400 (MSD) (envelope-from yuri.pankov@gmail.com) Received: (from yuri@localhost) by darklight.org.ru (8.14.4/8.14.4/Submit) id p36NKnF5014568; Thu, 7 Apr 2011 03:20:49 +0400 (MSD) (envelope-from yuri.pankov@gmail.com) X-Authentication-Warning: darklight.org.ru: yuri set sender to yuri.pankov@gmail.com using -f Date: Thu, 7 Apr 2011 03:20:49 +0400 From: Yuri Pankov To: Walt Pawley Message-ID: <20110406232049.GA3897@darklight.org.ru> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Cc: "freebsd-questions@freebsd.org" Subject: Re: Script behavior I can't grasp 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: Wed, 06 Apr 2011 23:43:16 -0000 On Wed, Apr 06, 2011 at 03:32:14PM -0700, Walt Pawley wrote: > My IPv6 tunnel has a tendency to vanish from time to time. So I > thought I might write a script to check that and attempt > reconstituting it if needed. After some considerable messing > about, I really thought this ... > > #!/bin/sh > if ifconfig en1|grep -q "inet6 2001" ; then exit; > else > if ps -ax | grep gw6c | grep -qv grep; > then ps -ax | grep gw6c | grep -v grep | ( read x y; kill "$x" ) > fi > cd /usr/local/gw6c/bin > ./gw6c > fi > > ... should work. But I was wrong, as usual. In the case where > the tunnel has vanished, the gw6c program often does not quit > right away, and it is usually soaking up a lot of processor in > that mode. Thus it was necessary to test for gw6c running and > terminate it if it was. Curiously, even when it was not > running. the test above would fail in the script. On the > command line, it seemed, as near as I could tell, to work just > fine. > > Grasping at straws, I decided to try the following: > > #!/bin/sh > if ifconfig en1|grep -q "inet6 2001" ; then exit; > else > if $( ps -ax | grep gw6c | grep -qv grep ); > then ps -ax | grep gw6c | grep -v grep | ( read x y; kill "$x" ) > fi > cd /usr/local/gw6c/bin > ./gw6c > fi > > It worked just fine. I'd like to know why this disparity. It's > probably something mind bogglingly simple but my researches > have yet to unboogle me. Can you? Not the answer you asked for, but... you should really take a look at pkill(1) instead of that check. HTH, Yuri