Skip to content

Instantly share code, notes, and snippets.

@kinjo kinjo/pfping
Last active Jun 19, 2016

Embed
What would you like to do?
A wrapper of fping to print pretty timestamp and host description.
#!/bin/bash
#
# A wrapper for fping to print pretty timestamp and host description.
#
# Copyright (C) 2016 Takumi KINJO - All Rights Reserved
# Permission to copy and modify is granted under the MIT license
# Version 0.1.0
# Licence: MIT
usage()
{
cat <<EOF
A wrapper of fping to print pretty timestamp and host description.
This requires -f to print host description. The rest is same as fping.
See also man fping.
EOF
exit 1
}
pretty-print()
{
sed -u -e 's/^\[\([^]]*\)\]/echo "["$(date --date=@\1)"]/' -e 's/\(.*\)\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\)\(.*\)/\1\2\3" $(grep \2 '$(echo $1 | sed 's/\//\\\//g')' | sed "s\/.*#\/#\/")/' | bash
}
while getopts f:h OPT 2> /dev/null
do
case $OPT in
f) hostfile="$OPTARG"
;;
h) usage
;;
\?)
;;
esac
done
if [ "$hostfile" = "" ]
then
usage
fi
fping "$@" | pretty-print "$hostfile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.