UNIX / Linux Shell Script For Monitoring System network with ping command

Posted on in Categories Monitoring last updated August 1, 2009

39 comment

  1. In my personal version I modified the program with this:

  2. N00b talking: How do i get my box with crunchbang on it get to email the notification? The script runs tĥrough, but it doesnt email, because my smtp requires authentification. (im not able to make the script pass this auth.)

    Thanx a lot for help, using this for monitoring a big Wireless system with lots of ips.(nonprofit)

  3. Hi,

    In this script while executing we get multiple mails for multiple servers mentioned how to get all server details in one single mail which loop should i remove in this

  4. I welcome! Prompt me as to adjust this script on constant repetition if ping is ok? If no ping send 1 msg and exit? cron not to offer.

  5. #!/bin/bash

    # add ip / hostname separated by white space
    HOSTS=”YOU CAN ADD MULTIPLE IP’S HERE”
    # no ping request
    COUNT=1

    for myHost in $HOSTS;
    do
    count=ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }'
    if [ $count -eq 0 ]
    then
    echo $myHost “WHAT EVER YOU WANT OUTPUT TO SAY”
    else
    echo $myHost “WHAT EVER YOU WANT OUTPUT TO SAY”
    fi
    done

    The “then” statement between quotes is what will be displayed if online

    The “else” statement between quotes is what will be displayed if not online

    1. Hi Lewcipher,

      From the below script if any ping goes down it immediately throws a mail. But how to configure this script if ping is (okay) it should shoot a mail that all are okay.

      Can u please help me.

      # add ip / hostname separated by white space
      HOSTS=”cyberciti.biz theos.in router”

      # no ping request
      COUNT=1

      # email report when
      SUBJECT=”Ping failed”
      EMAILID=”[email protected]
      for myHost in $HOSTS
      do
      count=$(ping -c $COUNT $myHost | grep ‘received’ | awk -F’,’ ‘{ print $2 }’ | awk ‘{ print $1 }’)
      if [ $count -eq 0 ]; then
      # 100% failed
      echo “Host : $myHost is down (ping failed) at $(date)” | mail -s “$SUBJECT” $EMAILID
      fi
      done

      Regards,
      Aryan

  6. Quick question:
    If I set the ping count to 4 and only one of four will failed will I get the true positive alarm anyway?

  7. How can I put this script on my dd-wrt router so it sends me alerts when one of the pc goes down? I don’t how to make run from my router. any suggestions.

    Thanks

Leave a Comment