How to check a list of hosts for connectivity issues

Imagine you have a big list of hosts called hosts-list. You would like to check if these hosts are pingable.

Here is a sample command which will do it:

for i in `cat hosts-list`; do ping “$i” -c2 2>1 > /dev/null || echo “$i is down”; done

The above pings each entry in the hosts list with 2 packets. If the ping status is not success (0 return code) the host’s name is said to be down.