Skip to content

Instantly share code, notes, and snippets.

@greatghoul
Created November 14, 2016 02:57
Show Gist options
  • Save greatghoul/e84039b5f12128f734959de00118be3c to your computer and use it in GitHub Desktop.
Save greatghoul/e84039b5f12128f734959de00118be3c to your computer and use it in GitHub Desktop.
Ping multiple hosts and sort result by avg duration
#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