Skip to content

Instantly share code, notes, and snippets.

@4fthawaiian
Created September 23, 2022 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 4fthawaiian/8d766a8a041357eef1765ca36fd13514 to your computer and use it in GitHub Desktop.
Save 4fthawaiian/8d766a8a041357eef1765ca36fd13514 to your computer and use it in GitHub Desktop.
i needed a ping that would run constantly and keep track of misses, etc - obvs a work in progress but here goes
#!/usr/bin/zsh
status() {
OUTPUT="===hello==="
[[ ! -z $1 ]] && OUTPUT=$*
# Save cursor pos
tput sc
# Change scroll region to exclude first line
tput csr 1 $((`tput lines` - 1))
# Move to upper-left corner
tput cup 0 0
# Clear to the end of the line
tput el
# Create a header row
echo -n "*** ${OUTPUT} ***"
# Restore cursor position
tput rc
}
if [[ ! -z $1 && $1 == "--status" ]]; then
shift
status $*
exit
fi
HOST=8.8.8.8
[[ ! -z $1 ]] && HOST=$1
clear
echo
status pinging $HOST
ping $HOST | awk -v HOST=$HOST '
BEGIN {
counter=1
series=1
fails=0
}
{
if(/icmp_/) {
series=substr($5,10)
time=substr($7,6)
system("'$0' --status pinging "HOST" "series" \\("fails" failed pings\\)")
if(series == counter) {
print "ping#"series"("counter") "time"ms"
} else {
fails++
}
counter++
}
if(transmitted) { print $0 }
}
'
@4fthawaiian
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment