Last active
August 29, 2015 14:18
-
-
Save vik-y/688bf0954c6c8d3f4dcb to your computer and use it in GitHub Desktop.
Shell Script to test internet connection at IIIT-B
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
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
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