Skip to content

Instantly share code, notes, and snippets.

@anatawa12
Created March 29, 2023 13:30
Show Gist options
  • Save anatawa12/4edb9b97b8726bea726b2adc48b03abd to your computer and use it in GitHub Desktop.
Save anatawa12/4edb9b97b8726bea726b2adc48b03abd to your computer and use it in GitHub Desktop.
ping.sh
#!/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