Quickly check hosts with ping

I needed a script for a quick health check of a bunch of servers.
This is how I did it using the ping command:

for((i=1;i<42;i++)); do
    ping -c 1 -W 3 host${i}.domain.com &> /dev/null
    if [ $? -ne 0 ] ; then
        echo "host${i} is down"
        echo "host${i} is up"

You can also use netcat and check a specific port:

netcat -z -w 2  host${i}.domain.com 80 &> /dev/null
  • damnit321

    tnx been looking for something simple like that