Last active
September 19, 2020 00:40
-
-
Save PetengDedet/d6173b8dffc7cc2c3fcf9e59dac4748e to your computer and use it in GitHub Desktop.
Script to tell you that ping is reply or not on macos
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
#!/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