Created
March 29, 2023 13:30
-
-
Save anatawa12/4edb9b97b8726bea726b2adc48b03abd to your computer and use it in GitHub Desktop.
ping.sh
This file contains hidden or 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/sh | |
PINGOPTIONS= | |
case "$(uname --kernel-name)" in | |
*cygwin*|*CYGWIN*|*mingw*|*MINGW*|*msys*|*MSYS*) | |
PINGOPTIONS="$PINGOPTIONS -t -w 1000" | |
;; | |
esac | |
# shellcheck disable=SC2086 | |
ping $PINGOPTIONS "$1" | while read -r line; do | |
if printf "%s" "$line" | grep "from.*time=" > /dev/null; then | |
printf "\33[2K%s -- %s\r" "$(date +"%Y/%m/%d %H:%M:%S")" "$line"; | |
else | |
printf "\33[2K%s -- %s\n" "$(date +"%Y/%m/%d %H:%M:%S")" "$line"; | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment