Created
September 23, 2022 02:59
-
-
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
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
#!/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 } | |
} | |
' | |
Author
4fthawaiian
commented
Sep 23, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment