Created
November 14, 2016 02:57
-
-
Save greatghoul/e84039b5f12128f734959de00118be3c to your computer and use it in GitHub Desktop.
Ping multiple hosts and sort result by avg duration
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
#script to ping multiple websites | |
#add websites you want to ping to the websites.txt file | |
#the output will be saved into results.txt | |
websitesFile=websites.txt | |
websiteList=$(cat $websitesFile |tr "\n" " ") | |
websites=($websiteList) | |
timeOut=1 | |
outputFile=results.txt | |
printf "Pinging %d websites from %s\n" "${#websites[@]}" $websitesFile | |
echo '\c' > $outputFile | |
for i in "${websites[@]}" | |
do | |
ping -o -t $timeOut $i \ | |
| grep round-trip \ | |
| awk -v host="$i" '{split($4, a, "/"); print host,a[1]}' \ | |
>> $outputFile | |
echo '.\c' | |
done | |
echo "\n\nMost fastest 10 websites are:" | |
echo '----------------------------' | |
sort -nk2 $outputFile | head -n 10 | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment