Check Machines Network Status
Posted on | January 23, 2010 | 2 Comments
This is a little script I wrote some time ago for a friend in a big ISP. It could be also useful for someone. Feel free to use it.
#!/bin/bash
###################################
# Check Machines Network Status #
###################################
# bY Marco Rodrigues (Kmos) in 2k #
# http://Marco.Tondela.org #
###################################
# Results:
# - Answers without problems (UP)
# - Not responding (DOWN)
# - Unknown host (DNS not configured)
# Ask range of machines to ping.
printf "\nPlease enter the hostnames that you want to check: (e.g: console{1..100}.pt1)\n"
read consoles_to_check
# Check hosts and ping results.
for console in `bash -c "echo $consoles_to_check"` ; do
if [ -x '/bin/ping' ] ; then
PINGTEST=`/bin/ping -c 1 $console 2>&1`
if [ -n "`echo $PINGTEST | grep -o '100% packet loss'`" ] ; then
result="DOWN"
elif [ -n "`echo $PINGTEST | grep -o '0% packet loss'`" ] ; then
result="UP"
elif [ -n "`echo $PINGTEST | grep -o 'unknown host'`" ] ; then
result="DNS not configured"
fi
else
result="Error: Ping is not correctly installed..."
fi
echo $console ":" $result
done
exit 0
Comments
2 Responses to “Check Machines Network Status”
Leave a Reply


58
57
7
3
0
42
20
7
6
4
0
0
0
0
0
0
0
February 3rd, 2010 @ 11:31 am
Ok está bonito e recomenda-se, mas entao…
e o nagios? Poupa esse trabalho todo e tem uma abordagem mais profissional.
February 3rd, 2010 @ 11:51 am
Sim, o Nagios tem isso e muito mais.. mas na altura foi o que me pediram =) provavelmente não usavam o Nagios.