How to get percentage of package loss

Due to testing on the network, the package lost rate is needed. The following bash script shows how to get percentage of package loss. I split IP address to four segments since it will be easy to manipulate for loop.

PINGTMP=/tmp/ping.tmp

IP_1=`echo $IPADDRESS | awk -F”.” ‘{print $1}’`
IP_2=`echo $IPADDRESS | awk -F”.” ‘{print $2}’`
IP_3=`echo $IPADDRESS | awk -F”.” ‘{print $3}’`
IP_4=`echo $IPADDRESS | awk -F”.” ‘{print $4}’`
ping -t 5 -c 2 $IP_1.$IP_2.$IP_3.$IP_4 > $PINGTMP
pack_loss=`awk ‘/statistics/{getline;print $6}’ $PINGTMP`
echo $pack_loss

Discussion Area - Leave a Comment




Spam Protection by WP-SpamFree Plugin