Return to Snippet

Revision: 1006
at August 28, 2006 10:34 by sudarkoff


Initial Code
One that checks if there is a default gateway and if so pings it and displays both the gateway and the response time:
Code:	

shopt -s extglob
GW=$(netstat -rn|grep ^default|awk '{print $2}')
if [[ ! $GW == +([[:digit:]]).+([[:digit:]]).+([[:digit:]]).+([[:digit:]]) ]]; then
   echo "no default gateway"
   exit 1
fi
IFS=''
PING=`ping -c1 -n -t5 -o $GW`
RC=$?
if [ $RC -eq 2 ]; then
   echo "gateway ($GW) no reply"
   exit 1
fi
RT=$( echo $PING | head -n2 | tail -n1 | awk -F= '{print $4}' )
echo "gateway ($GW) $RT"
exit $RC

Initial URL
http://projects.tynsoe.org/phpBB2/viewtopic.php?p=745

Initial Description


Initial Title
Find and ping default gateway

Initial Tags
Bash

Initial Language
Other