If this will help, I wrote the 2 scripts (below)
to do something similar as you are trying to do.
except in my case, my cable modem needs to
be reset, so I echo out to the serial port and
a circuit attached to the serial port will interrupt
the power to my cable modem. But just
change my echo to the serial to what ever
you want your system to do (like restart your network)
To run them, I have a cron that runs "checkem" every
10 min. (checkem will call pingcheck). I have the
files located in /usr/local/bin.
Hope this helps
Chuck

This is the file I called "checkem"
host1=www.sun.com
host2="www.yahoo.com"
host3="www.google.com"

bad_count=0
if [ `pingcheck $host1` = 0 ]
then
    bad_count=$(($bad_count + 1))
fi
if [ `pingcheck $host2` = 0 ]
then
    bad_count=$(($bad_count + 1))
fi
if [ `pingcheck $host3` = 0 ]
then
    bad_count=$(($bad_count + 1))
fi
if [ $bad_count -gt 2 ]
then
    echo "** Cable Modem Reset **" >> /var/log/syslog
    echo "HELLO" > /dev/ttyS0
#else
#    echo "Cable Modem  OK"
fi

This is the file I called "pingcheck"

#!/bin/sh
host=$1
result=`ping $host -c 1 | grep "1 packets received"`
if [ -z "$result" ]
then
    echo 0
else
    echo 1
fi


----- Original Message -----
From: "Erich Titl" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, May 29, 2002 9:38 AM
Subject: Re: [leaf-user] Detecting Disconnected Network


Hi Kiril

If I read your script correctly then there might be a little glitch

At 18:49 28.05.2002 -0700, you wrote:
>my last version of the script for pinging hosts follows. if there is a more
>elegant and reliable way to react in such rare situations, i will be glad
to
>hear it.
>
>regards,
>
>kiril
>
>
>
>#!bin/bash
>PING_REMOTE_HOSTS="host1.com host2.com host3.com"
>
>for HOST in $PING_REMOTE_HOSTS
>do
>         UP=0
>         while [ $UP -eq 0 ]
>         do
>                 sleep 120
>                 ping $HOST -qc 1 >/dev/null 2>&1
>                 UP=$?
>         done
>         echo "$HOST is down, trying next host..."
>done

Once you have wasted all the hosts in your list you restart your network,
although IMHO this only means that host3.com cannot be pinged.

I believe you want to do something like

#!bin/bash
PING_REMOTE_HOSTS="host1.com host2.com host3.com"

UP=0
while true
do

     while [$UP -eq 0]
     do
         sleep 120
         UP = 1       # this would break the inner loop

         for HOST in $PING_REMOTE_HOSTS
         do
             ping $HOST -qc 1 >/dev/null 2>&1
             UP &= $?    # if any ping returns 0 it is OK
         done

     done


echo "network is down. restarting..."
/etc/init.d/network reload
sleep 60

done

I have not tested this :-(

Erich

THINK
P�ntenstrasse 39
8143 Stallikon
mailto:[EMAIL PROTECTED]
PGP Fingerprint: BC9A 25BC 3954 3BC8 C024  8D8A B7D4 FF9D 05B8 0A16


_______________________________________________________________

Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm

------------------------------------------------------------------------
leaf-user mailing list: [EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/leaf-user
SR FAQ: http://leaf-project.org/pub/doc/docmanager/docid_1891.html


_______________________________________________________________

Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm

------------------------------------------------------------------------
leaf-user mailing list: [EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/leaf-user
SR FAQ: http://leaf-project.org/pub/doc/docmanager/docid_1891.html

Reply via email to