#!/bin/bash # # # connectivity_check v0.2 Oct. 16, 2006 # Written by Robert Pectol - http://rob.pectol.com/irlp/ # # Running this script will test the connectivity to your ISP's services (the Internet) # and can be called manually or from another script. It returns a, '0' with an exit # status of 0 if the connection is detected as being, 'good', else it returns a, '1' # with an exit status of 1. # ############################################################################################ pinghost=def.gwy.host.ip # this should be set to your Internet router's default gateway host's IP address packetcount=100 # 100 is enough to test the connection without, 'overloading' the target host packetsize=512 # 512 bytes is approximately the same size as the audio-data packets used by IRLP threshold=2 # this specifies the number of lost packets (threshold) to be considered acceptable # make sure the host is reachable result=`/bin/ping -c 1 -w 2 $pinghost 2>/dev/null | grep "1 received"` if [ "$result" != "" ]; then result="" pass=0 # if host is reachable, then ping flood with packets of specified size and count; try up to 3 times for a , 'passing' result while [[ "$pass" -lt "3" && "$result" == "" ]]; do result=`sudo /bin/ping -f -s $packetsize -c $packetcount $pinghost 2>/dev/null | grep 'packets transmitted' | cut -d ' ' -f6 | sed 's/%//'` if [ "$result" -lt "$threshold" ]; then # report the good news and exit echo "0" exit 0 fi pass=$(($pass + 1)) sleep .5 done # report the bad news and exit echo "1" exit 1 else # report the bad news and exit echo "1" exit 1 fi exit 0