vik-y
4/5/2015 - 12:52 PM

Shell Script to test internet connection at IIIT-B

Shell Script to test internet connection at IIIT-B

#!/bin/bash

echo "" > result.txt
date >> result.txt

echo "Zense" 

function test (){
	date
	echo " " 
	website=$1
	echo "TEST-1 $website"
	
	echo "Be patient, this can take a while (2-5 minutes) to complete"
	foo=$(ping -i $sleeptime -c $packets $website | grep rtt)
	echo "FOO: $foo"
	 
	echo $foo | awk -F' = ' '{print $2}' | awk -F'/' '{print "RTT Stats: \nMin: " $1 "\nAverage: " $2 "\nMaximum: " $3 "\nMdev: "$4}'
	
	 
	avg=$(echo $foo | awk -F' = ' '{print $2}' | awk -F'/' '{print $2}')
	 
	echo "AVG: $avg"
	result=$2	
	var=`echo "$avg<$result" | bc`          
	if [ $var -ne 1 ];then
		    echo "WARNING: Poor Connection with this site. Slow Internet suspected"
	else
		    echo "Latency for $website is ok, Seems to be working fine"
		    success=`expr $success + 1`
	fi
	
	echo "$website : $avg, Ideal:<$2" >> result.txt
	echo " " 
	echo " " 
	
}


packets=50 #number of ping packets which you want to send to each site
sleeptime=0.3 #the time for which yoiu want to sleep before you send a ping packet - to increase/decrease the ping rate 
sites=4 #Please increment this if you add any new site for testing 
success=0

 
#If you want to add any of your own sites for testing 
#Use: test <sitename> <ideal latency>  Also put the sites variable equal to the number of sites which you are putting in test for

test facebook.com 350
test google.com 40
test yahoo.com 300
test 192.168.3.254 10


echo "Copy and paste the output below on Google Doc link https://docs.google.com/forms/d/1DRqnE1jAXWli76C-RQTCnSgmYr5A8YFPshTdedxozek/viewform"

if [ $success -lt $sites ];then
		    echo "REPORT: Pooor Internet Suspected. Needs Improvement. Only $success out of $sites sites responding properly."
		    echo "REPORT: Pooor Internet Suspected. Needs Improvement. Only $success out of $sites sites responding properly." >> result.txt
		    
	else
		    echo "All passed"
		    echo  " " >> result.txt
		    echo "All passed" >> result.txt
		    success=`expr $success + 1`
	fi

echo " ------------Copy Below this Line ---------------------" 

cat result.txt