Last active
August 29, 2015 14:26
-
-
Save jstnlvns/f98a4b6399748f03c179 to your computer and use it in GitHub Desktop.
Pinging Multiple Hosts
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 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.