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

in Categories Monitoring last updated August 1, 2009

Share this on:

39 comment

  1. # add ip / hostname separated by while space

    should read

    # add ip / hostname separated by white space

    my understanding is that you want a space between hostnames
    not sure what a while space is
    sounds exciting though

  2. I’ll pose a silly question: is there a technique to return a result if the ping attempt fails fr the *local* pc?

    I’m attempting to adapt this script to troubleshoot/log a perceived flaky router (somehow still keeping the LAN-side running, abet very slow…), but as Swati & pituhdo have pointed out, it falls face down when the local connection fails.

    1. For IP address it will only return 0 (100% fail) or number of packets. Are you using hostname?

  3. I am getting an error
    line 9: [: -eq: unary operator expected

    Can someone help me on this

    1. @Swati

      This normally happens when a host in the HOSTS variable is not known for the machine.

    2. Hi Swati,

      I believe you have entered hostname instead of ip to test it out right?

      If it is unknown hostname , you are probably get this error message. Use IP for the test instead.

  4. After doing much much more googling I’ve finally found how to send mail. For the joys of others: you can do this by installing ssmtp and mailx.

    If ssmtp gives you hell installing it (like it did with me), then you should check the hostname of the computer. You can find this in /etc/hosts and you should have a line something like:
    “ yourhost.domain.local yourhost” (and use # to comment the rest out)

    After this you should be able to install ssmtp by typing:
    dpkg –purge ssmtp
    apt-get install ssmtp

    configure the ssmtp.conf that is in /etc/ssmtp and should look like this:

    And after all this, you can check if it works by typing:
    and ending the mail by typing “.”

    Good luck!!

  5. Great script! But I can’t get it to send an e-mail. I’ve just installed mailx, but don’t I need to specify the smtp-server for this to work?? I’ve tried the man-pages and googled around a bit, but I can’t find a solution…

  6. hi
    im new to shell scripts and im unable to understand the above code
    can anyone please explain the code above

  7. use this if you like neat one liners:
    [ $(ping -c1 $1 -W1 -w1 | awk ‘/received/ {print $4}’) -eq 1 ] && echo “ONLINE” || echo “OFFLINE”

  8. I think you’ve missed same characters at the start of the script. Sorry for my terrible english!!
    “imple”—> “# Simple”

  9. Hi,

    I create the file monitor.sh , set permission 755 , and run ./monitor.sh .

    the system reply :

    ./monitor.sh: line 1: imple: command not found

    can anyone help me ?

  10. I keep getting syntax error: unexpected end of file. Not sure why. The script seems correct to me.

    Have a question? Post it on our forum!