Skip to content

Instantly share code, notes, and snippets.

@vik-y
Last active August 29, 2015 14:18
Show Gist options
  • Select an option

  • Save vik-y/688bf0954c6c8d3f4dcb to your computer and use it in GitHub Desktop.

Select an option

Save vik-y/688bf0954c6c8d3f4dcb to your computer and use it in GitHub Desktop.
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
@vik-y

vik-y commented Apr 5, 2015

Copy link
Copy Markdown
Author

Increased the ping rate and added functions

@vik-y

vik-y commented Apr 5, 2015

Copy link
Copy Markdown
Author

I have put the sleeptime at 0.3 so that the ping requests are monitored over a longer time period rather than in small bursts. That would ensure correct measurements.

@sidd607

sidd607 commented Apr 5, 2015

Copy link
Copy Markdown

Use an & after every function Call. It runs the function as a separate.

test facebook.com 300 &
test google.com 40 &
test 192.168.3.254 10 &
wait #waits for the above processes to complete

@vik-y

vik-y commented Apr 13, 2015

Copy link
Copy Markdown
Author

That's great..but I thought it'd be better if the tests run sequentially.. but nice trick.. wil be useful later on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment