[SATLUG] program or cron job to ping internal devices & email

Bruce Dubbs bruce.dubbs at gmail.com
Wed Jan 16 11:07:48 CST 2008

twistedpickles wrote:
> Does know or have a program or cron job that can ping network devices and if
> down send out an email?

You can try some variation of:


function pingit
  echo -n "Pinging $1 "
  s=`ping -w$2 -q $1`
  echo $s | grep duplicate > /dev/null && field=-f20
  loss=`echo $s|cut -d" " $field`
  echo "--  $loss packet loss ($3)"

if [ $# -eq 0 ]; then timeout=10; else timeout=$1; fi

pingit   $timeout phobos0
pingit   $timeout venus0
pingit   $timeout deimos0


Note that there are a couple variations of the ping program.  You want
the one from iputils: http://www.linux-foundation.org/en/Net:Iputils

Check to see what verion of ping you have with `ping -V`.  What you need
is the -w option:

-w deadline
    Specify a timeout, in seconds, before ping exits regardless of how
many  packets  have  been  sent or received. In this case ping does not
stop after count packet are sent, it waits either for deadline expire or
until count probes are answered or for some error notification from network.

  -- Bruce

More information about the SATLUG mailing list