karlherrick.com

Pinglog

Tuesday, 24 October 2006

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


Home

About

Portfolio

Web Apps Web Enabled Applications Corporate Sites Personal Sites
Preferences Dark Theme Light Theme Notifications
Social GitHub LinkedIn RSS Feed Icon