icmp ping connection monitor script

This was one of those tasks that was quicker to write my own than it was to Google up one of the several hundred other identical monitoring scripts.

This script monitors whether or not a host is responding to ICMP and can be happily set to a resolution of 1 second. It’s written in bash and will happily run on my linux. It should run on yours, too.

./pingit 1 myHostname.dyndns.org > /var/log/myIspIsNotIdeal.log

if [ $# -ne 2 ]
  echo "Usage: $0 <timeout in seconds> <hostname to ping>"
  exit 1
while true
  echo -n "$(date) "
  ping -q -c 1 -W $1 $2 > /dev/null
  case $? in
    echo "down"
    echo "ok"
    sleep $1
    echo "the damage report machine has exploded"

Run it and redirect its output to a file for later grepping. Once I’m happy its bedded in and working, and I’ve finished tarting it about a bit, I’ll make it only output a line on failure.

If you’d prefer your monitoring to be slightly more capable than this, and also draw pretty rrdtool graphs of the results, then I recommend you check out Smokeping, which is in the Debian repositories and is very simple to set up.

One thought on “icmp ping connection monitor script

Comments are closed.