-
-
Save davidohne/6c21f9b73632105536ae0431ec70b4d2 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
#!/bin/bash | |
#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) | |
outputFile=results.txt | |
printf "Pinging %d websites from %s\n" "${#websites[@]}" $websitesFile | |
for i in "${websites[@]}" | |
do | |
ping -c3 -q $i \ | |
| grep rtt \ | |
| awk -v host="$i" '{split($4, a, "/"); print host,a[1]}' \ | |
>> $outputFile | |
echo Ping sent to "$i" | |
done | |
echo "Most 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