Pinglog

The ability to ping a host can be such a useful tool in establishing network connectivity. Being able log such activity is quite valuable also. Below is a short bash script that can assist you in those endeavors.

#!/bin/bash
logname=`date "+%Y-%m-%d-%H-%M-%S"`-$1.log
if [ "$1" = "-help" ]; then
   echo "Usage: pinglog.sh [HOST]"
   echo "Usage: pinglog.sh [OPTION] [LOGFILE] [HOST]"
   echo "Log pings of the HOST."
   echo ""
   echo "[HOST]   | shortname of the station to be logged."
   echo "[OPTION] | one option available. –missed-pings"
   echo ""
   echo "-missed-pings     shows the date and time a ping was"
   echo "                  missed from a generated log file"
   echo ""
   echo "Usage examples: pinglog.sh wiretop"
   echo "                pinglog.sh -missed-pings"
   echo "                   2007-04-10-02-12-22-wiretop.log wiretop"
   echo ""
   echo "pinglog.sh will log the ping information into the same"
   echo "directory"
   echo "that it was started from in a file called 'ping.log'"
elif [ "$1" = "-missed-pings" ]; then
   cat $2 | grep -v $3
elif [ -z "$1" ]; then
   echo "pinglog.sh: too few arguments"
   echo "Try 'pinglog.sh -help' for more information."
else
   while true; do
      echo "$(date) $(ping -c 1 $1 | grep time=)" >> $logname
      sleep 1
   done
fi
This entry was posted on Monday, October 23rd, 2006 at 9:54 pm. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Responses to “Pinglog”

  1. Karl Herrick Says:

    I changed the source code to read, “-help” and “-missed-pings” because semgeshicodefix doesn’t like {dash}{dash}… didn’t have enough time to track down what the problem is… here’s a {dash}{dash}help after parsed by semgeshicodefix… –help

  2. Karl Herrick Says:

    And of course, you could always use Cacti.

Leave a Reply