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”

  1. Alex
    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.

  2. Marco
    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.

Leave a Reply







Who Am I ?

I'm Marco Rodrigues and I currently work in Luxembourg as System Administrator.

Contact me.








Subscribe to my feed

Search

    Writing

    26 articles
    1491 comments

      Comments

      platforms
      windows 1431
      linux 21
      macos 3
      sun 0
      wp 0

      browsers
      ie 1361 
      opera 66 
      firefox 52 
      safari 14 
      chrome 11 
      bonecho 0 
      flock 0 
      epiphany 0 
      konqueror 0 
      iceweasel 0 
      lynx 0 
      netnewswire 0