Date: Thu, 7 Apr 2011 03:20:49 +0400 From: Yuri Pankov <yuri.pankov@gmail.com> To: Walt Pawley <walt@wump.org> Cc: "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org> Subject: Re: Script behavior I can't grasp Message-ID: <20110406232049.GA3897@darklight.org.ru> In-Reply-To: <p0624085cc9c2991516e2@[10.0.0.10]> References: <p0624085cc9c2991516e2@[10.0.0.10]>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110406232049.GA3897>