HowTo ping a Lot of hosts for up|down
Posted: Sat Mar 24, 2012 8:17 pm
Couldn't find one that worked readily, so I made one.
This script is by NO means conclusive or as complete as it could be (needs an alternate check method (Hint Hint Nudge Nudge Wink Wink)... icmp "may" be blocked on some hosts and that will fail in the script and come back as "down", that's not the script's fault. )
Step1:
Make list of hosts (actual or FQDN or a mash of both...)
save it as say ~/Documents/ping.list
Step2:
Edit /etc/hosts as root and add your IP/hosts details:
Step2:
Create this .sh script and add:
save it as say ~/bin/ping_hosts.sh
Now run it:
Output:
Other more elegant solutions may exist (That's my standard disclaimer folks)
This code is just me hacking for my own creative ends while serving a need.
Enjoy.
This script is by NO means conclusive or as complete as it could be (needs an alternate check method (Hint Hint Nudge Nudge Wink Wink)... icmp "may" be blocked on some hosts and that will fail in the script and come back as "down", that's not the script's fault. )
Step1:
Make list of hosts (actual or FQDN or a mash of both...)
Code: Select all
grid1
grid2
c9Zabbix
C9_Prod_Bacula
c9gluster-nas1
c9gluster-nas2
Cirrhus9_Prod_sFTP
Cirrhus9_Prod_Wiki
MikeJ_WinServer
Cirrhus9_JJ_LAMP
cirrhus9b
webdev
Icinga/Cacti
drupal3
varnish3
remotedb2
nfs
web1
web2
rsgrid1
rsgrid2
rsgrid3
Step2:
Edit /etc/hosts as root and add your IP/hosts details:
Code: Select all
xx.xxx.246.198 grid1
xx.xxx.224.34 grid2
xx.xxx.224.62 c9Zabbix
xx.xxx.224.35 C9_Prod_Bacula
xx.xxx.224.53 c9gluster-nas1
xx.xxx.224.54 c9gluster-nas2
xx.xxx.224.36 Cirrhus9_Prod_sFTP
xx.xxx.224.38 Cirrhus9_Prod_Wiki
xx.xxx.224.47 MikeJ_WinServer
xx.xxx.224.45 Cirrhus9_JJ_LAMP
xx.xxx.181.212 c9a
xx.xxx.139.254 cirrhus9b
xx.xxx.207.18 webdev
xx.xxx.171.149 Icinga/Cacti
xx.xxx.121.73 drupal3
xx.xxx.121.78 varnish3
xx.xxx.155.196 remotedb2
xx.xxx.131.124 nfs
xx.xxx.130.234 web1
xx.xxx.131.126 web2
xx.xxx.143.152 rsgrid1
xx.xxx.128.55 rsgrid2
xx.xxx.27.48 rsgrid3
Create this .sh script and add:
Code: Select all
#!/bin/bash
# Written by John Jones of cirrhus9.com
is_alive_ping()
{
if
ping -c 1 $1 > /dev/null ; then
[ $? -eq 0 ] && echo $i is up
else
echo $i \""may\"" be down
fi
}
for i in $(cat ~/Documents/ping.listt)
do
is_alive_ping $i
done
#EOF
Code: Select all
chmod 700 ~/bin/ping_hosts.sh
Code: Select all
~/bin/ping_hosts.sh
Code: Select all
grid1 is up
grid2 is up
c9Zabbix is up
C9_Prod_Bacula is up
c9gluster-nas1 "may" be down
c9gluster-nas2 "may" be down
Cirrhus9_Prod_sFTP is up
Cirrhus9_Prod_Wiki is up
MikeJ_WinServer is up
Cirrhus9_JJ_LAMP is up
cirrhus9b is up
webdev is up
Icinga/Cacti is up
drupal3 is up
varnish3 is up
remotedb2 is up
nfs is up
web1 is up
web2 is up
rsgrid1 is up
rsgrid2 is up
rsgrid3 is up
This code is just me hacking for my own creative ends while serving a need.
Enjoy.