Skip to content

Instantly share code, notes, and snippets.

@jstnlvns
Last active August 29, 2015 14:26
Show Gist options
  • Save jstnlvns/f98a4b6399748f03c179 to your computer and use it in GitHub Desktop.
Save jstnlvns/f98a4b6399748f03c179 to your computer and use it in GitHub Desktop.
Pinging Multiple Hosts
#!/bin/bash
rm /var/www/html/out.html
HOSTS="www.google.com www.duckduckgo.com www.stackoverflow.com"
COUNT=5
dd=$(date)
echo "<html><body>$dd<table><tr><th>HOST</th><th>STATUS</th></tr>" >> /var/www/html/out.html
for myHost in $HOSTS;
do
count="$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $3 }' | awk '{ print $1 }')"
if [ "$count" = "100%" ]; then
echo "<tr><td>$myHost</td><td align='center' valign='center'> <img src='down.gif' style='height:30px'></td></tr>" >> /var/www/html/out.html
elif [ "$count" = "0%" ]; then
echo "<tr><td>$myHost</td><td align='center' valign='center'> <img src='up.gif' style='height:30px'></td></tr>" >> /var/www/html/out.html
else
echo "<tr><td>$myHost</td><td align='center' valign='center'> <img src='inter.gif' style='height:30px'></td></tr>" >> /var/www/html/out.html
fi
done
echo "</table></body></html>" >> /var/www/html/out.html
@jstnlvns
Copy link
Author

This is a simple script for pinging multiple hosts. I direct the output to an html file created by the script so I can check via a browser within our network.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment