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 ?

Hi!

I'm Marco Rodrigues with 25 years old and I live near Viseu, Portugal.
I usually work as Web Developer / Systems Administrator, specially with Open Source technologies. I'm available to work as freelancer.

Contact me.








Subscribe to my feed

Search


    Writing

    22 articles
    133 comments

      Comments

      platforms
      windows 58
      wp 57
      linux 7
      macos 3
      sun 0

      browsers
      ie 42 
      firefox 20 
      safari 7 
      opera 6 
      chrome 4 
      bonecho 0 
      epiphany 0 
      flock 0 
      konqueror 0 
      iceweasel 0 
      lynx 0 
      netnewswire 0