From owner-freebsd-questions@FreeBSD.ORG Wed Apr 6 23:08:05 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 D3D4E1065677 for ; Wed, 6 Apr 2011 23:08:05 +0000 (UTC) (envelope-from walt@wump.org) Received: from que11.charter.net (que11.charter.net [209.225.8.21]) by mx1.freebsd.org (Postfix) with ESMTP id 6DDC78FC1C for ; Wed, 6 Apr 2011 23:08:04 +0000 (UTC) Received: from imp09 ([10.20.200.9]) by mta31.charter.net (InterMail vM.7.09.02.04 201-2219-117-106-20090629) with ESMTP id <20110406223222.YAYP12685.mta31.charter.net@imp09> for ; Wed, 6 Apr 2011 18:32:22 -0400 Received: from [10.0.0.10] ([71.80.206.85]) by imp09 with smtp.charter.net id UNYL1g00G1r4kY705NYMjd; Wed, 06 Apr 2011 18:32:22 -0400 X-Authority-Analysis: v=1.1 cv=oIv04XXdEYh2MbYuDfZqeaswiw9+RGe2txZblPR/Lr4= c=1 sm=1 a=7od6AAemV74A:10 a=kj9zAlcOel0A:10 a=g/lYYY1YV9Rstnml5ZDZhA==:17 a=ebNzH6DdAAAA:8 a=9j6YtuA8ixKgNJH6hDoA:9 a=bpmHMFwRd2izueHMlsIA:7 a=CjuIK1q_8ugA:10 a=Z-IikAJXHoYA:10 a=zbkDLoAsQ4cA:10 a=g/lYYY1YV9Rstnml5ZDZhA==:117 Mime-Version: 1.0 Message-Id: Date: Wed, 6 Apr 2011 15:32:14 -0700 To: "freebsd-questions@freebsd.org" From: Walt Pawley Content-Type: text/plain; charset="us-ascii" Subject: 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:08:05 -0000 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? -- Walter M. Pawley Wump Research & Company 676 River Bend Road, Roseburg, OR 97471 541-672-8975