On Thu, 30 Dec 1999,  Scott Felton wrote about,  Re: Shell script pinging for HR6.1:
> On 30 Dec, Richard Adams wrote:
> 
> > The reason the origanal script gives an error is the two &&'s and the
> > redirect to /dev/null. The script does not work like it used to either,
> > things have changed, ping returns 0% packet loss not 0 packets, so there
> > will be nothing zero.
> 
> Hello Richard (and other newbies and gurus). I'm not very familiar with
> shell scripts (my understatement of the year). I don't know why the
> original I pulled from the Dynamic-IP-Hacks HOWTO has the redirection
> to /dev/null (I assume because I don't want the result on my terminal)
> and I have no idea why it has two && at the end.
> 
> My modified script now reads...
> 
> #!/bin/sh
> #
> # Script to keep the ppp0 port up
> #
> if [ -f /var/run/ppp0.pid ] ; then
>  ping -c5 -l3 204.249.184.2 2>&1 | grep "0 packets" > /dev/null && \
>  { /usr/sbin/ppp-off > /dev/null 2>&1 ; sleep 2 ; /usr/sbin/ppp-go; }
> else
>  /usr/sbin/ppp-go
> fi
> # Done
> 
> >From what I understand, this says "If I find ppp0 in use, then ping
> this address 5 times and look for the string "0 packets" (which
> indicates my connection has been lost). If it matches "0 packets" then
> shut down my ppp connection, wait 2 seconds and fire up the ppp
> connection again. Else (if no ppp0 pid is found) just fire up ppp to
> begin with. If I grep for "0%", wouldn't that mean I have NO packet
> loss in which case I don't want the other stuff to happen?

Ah!, after looking closer i see what the grep is looking for, the
misleading thing is that the return of the ping session is;

5 packets transmitted, 5 packets received, 0% packet loss

If one or the other return a 0 (transmitted or sent) then it means the line
is down and promptly starts it again. I got confused about the 0% packet
loss, which turns out to be irrelavant to this subject.

> Also, my error was coming from the original script missing the
> semi-colon after the "/usr/sbin/ppp-go" between the braces. When I
> added that third semi-colon, the errors quit. I'm still not sure the
> script is working correctly but at least I don't have a new mail in
> root's mailfile every 5 mins :)

Yes i noticed it after i had edited the scrit around a bit, that is
exachtly what i meant in my other mail about making a script global, or at
least its an example of how syntax has to change to accomodate other
commands.


> 
> For the fellow that wanted to use a similar script under RH, I don't
> see why the above wouldn't work if you just substitute whatever you run
> for a ppp connection for the ppp-go above and whatever you run to shut
> down ppp for the ppp-off above. (I don't know anything about how Red
> Hat does it's ppp connection).

The scrpit as is, should work on all distros. One would need to check the
path's for the ppp-off and go scripts tho'.

Anyway have a happy pinging new year.

> 
> 
> -- 
> Scott Felton WF3R
> [EMAIL PROTECTED]
> http://www.k3ir.ampr.org
> Slackware Linux
-- 
Regards Richard
[EMAIL PROTECTED]
http://people.zeelandnet.nl/pa3gcu/
Happy New Year

Reply via email to