Skip to content

Instantly share code, notes, and snippets.

@PetengDedet
Last active September 19, 2020 00:40
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 PetengDedet/d6173b8dffc7cc2c3fcf9e59dac4748e to your computer and use it in GitHub Desktop.
Save PetengDedet/d6173b8dffc7cc2c3fcf9e59dac4748e to your computer and use it in GitHub Desktop.
Script to tell you that ping is reply or not on macos
#!/bin/bash
CONNECT_STATE=0
PREVIOUS_STATE=0
while true; do
if ping -c 1 google.com | grep "64 bytes from"; then
CONNECT_STATE=1
else
CONNECT_STATE=0
fi
if [[ ${PREVIOUS_STATE} != ${CONNECT_STATE} ]]; then
((PREVIOUS_STATE = CONNECT_STATE))
if [[ ${CONNECT_STATE} == 0 ]]; then
say "disconnected"
else
say "connected"
fi
fi
sleep 2
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment