Skip to content

Instantly share code, notes, and snippets.

@davidohne
Forked from greatghoul/pingall.sh
Last active March 25, 2020 09:18
Show Gist options
  • Save davidohne/6c21f9b73632105536ae0431ec70b4d2 to your computer and use it in GitHub Desktop.
Save davidohne/6c21f9b73632105536ae0431ec70b4d2 to your computer and use it in GitHub Desktop.
Ping multiple hosts and sort result by avg duration
#!/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