Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 Apr 2011 15:32:14 -0700
From:      Walt Pawley <walt@wump.org>
To:        "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org>
Subject:   Script behavior I can't grasp
Message-ID:  <p0624085cc9c2991516e2@[10.0.0.10]>

next in thread | raw e-mail | index | archive | help
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 <walt@wump.org>
Wump Research & Company
676 River Bend Road, Roseburg, OR 97471
         541-672-8975



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?p0624085cc9c2991516e2>