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"
else
echo "host${i} is up"
fi
done
You can also use netcat and check a specific port:
netcat -z -w 2 host${i}.domain.com 80 &> /dev/null
This entry was written by , posted on August 14, 2009 at 1:46 pm, filed under Command line and tagged loop, netcat, ping. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
tnx been looking for something simple like that