Last active
June 19, 2016 16:41
-
-
Save takumikinjo/41fc39187c8f378d0152bd74421beb9e to your computer and use it in GitHub Desktop.
A wrapper of fping to print pretty timestamp and host description.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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