Cover V10, I06
Article
Listing 1
Listing 2

jun2001.tar


Listing 1 if_check.sh

#!/bin/sh
#
# 2001-01-30 Tom Kranz (thomas.kranz@flutter.com)
#
# We return the following error codes:
# 0 - network connectivity is OK as it as - apart from annoyingly printing
#     'Woohoo' nothing has happened
# 1 - something's fubar on the network, and we've had to swap interfaces
# 2 - you didn't enter a IP address to ping to test connectivity - we'll
#     print a nice error message and then leave

if [ $# -ne 1 ]
then
        echo
        echo "Usage: if_checker.sh <IP_address_to_ping>"
        echo 
        echo "Where <IP_address_to_ping> is an always-reachable address you can"
        echo "use to verify connectivity"
        echo
        exit 2
fi

if /usr/sbin/ping $1 
then
        echo "Woohoo!"
        exit 0
else
        upif="`/usr/sbin/ifconfig -a | grep -v LOOPBACK | grep UP | cut -b 1-4`"
        downif="`/usr/sbin/ifconfig -a | grep -v LOOPBACK | grep -v UP | grep RU \
           NNING | cut -b 1-4`"
        /usr/sbin/ifconfig $upif down
        /usr/sbin/ifconfig $downif up

fi

/usr/sbin/ping $1
exit 1