[X-Unix] How to determine which network component is failing

Charles Howse chowse at charter.net
Wed Jul 26 16:49:22 PDT 2006


On Jul 25, 2006, at 11:20 PM, Stroller wrote:

> This grepping for "offline" seems a little contrived, if you'll  
> excuse me mentioning it.
>
> You set an exit staus with your script, so why not trust others to  
> do so, too?

How does this grab ya?  Works as expected, except the values returned  
are retained by the shell until I quit Terminal and restart it.  Was- 
up-wid-dat?

#!/bin/bash

until [ "$choice" = "q" ]
do

echo
echo
echo "Choose an action"
echo "---------------------------------------------"
echo "a. Ping 3 Internet hosts."
echo "b. Get Internet IP address from router."
echo "c. Release and Renew DHCP address."
echo "d. Get Signal Levels from Cable Modem."
echo "e. Reboot the Cable Modem."
echo "q. Quit."
echo "---------------------------------------------"
echo -n "Your choice?:"
read choice
case "$choice" in
"A" | "a" )
ping -c 3 google.com > /dev/null
if [ $? -le 2 ] ; then
	echo Google appears to be online
else
	echo Google appears to be offline
fi

ping -c 3 freebsd.org > /dev/null
if [ $? -le 2 ] ; then
	echo FreeBSD appears to be online
else
	echo FreeBSD appears to be offline
fi

ping -c 3 Yahoo.com > /dev/null
if [ $? -le 2 ] ; then
	echo Yahoo appears to be online
else
	echo Yahoo appears to be offline
fi
;;
"B" | "b" )
	curl -u admin:password http://192.168.254.254/Status_Router.htm 2> / 
dev/null | grep -o '[[:digit:]]\{1,3\}[\.][[:digit:]]\{1,3\}[\.] 
[[:digit:]]\{1,3\}[\.][[:digit:]]\{1,3\}' | head -1
;;
"C" | "c" )
	curl -u admin:password "http://192.168.254.254/Gozila.cgi?dhcpAction=0"
	sleep 5
	curl -u admin:password "http://192.168.254.254/Gozila.cgi?dhcpAction=1"
;;
"D" | "d" )
	curl -s http://192.168.100.1/signaldata.html | grep dB | tr -d \<TD 
\> | tr -d /
;;
"E" | "e" )
	curl -d "BUTTON_INPUT=Restart%20Cable%20Modem" 192.168.100.1/ 
configdata.html
;;
	"Q" | "q" )
	exit 0
;;
esac
done
exit 0


--
How I make Great Barbecue -
http://bubbabbq.homeunix.net/bbq.html




More information about the X-Unix mailing list