Script: Checking Alive Servers from a Server List

With a list of servers, it is common that one or more are down or crash. Lots cluster management tools can detect the aliveness of servers. However, it can be easily done with ping with a Bash script.

I summarize the script that I used and share it here:


usage: ./ file
Each host in one line in the file

The mechanism and tool used behind this is quite straightforward: just ping (that’s right, the ping command) the host and check the results. For example, to check whether a server $line is alive:

ping -W1 -c1 $line | grep received | awk '{print $4}

This produces “0” if the server can not be reached by ping (very possibly down).

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *