Skip to content

Instantly share code, notes, and snippets.

@PetengDedet

PetengDedet/ping_say.sh

Last active Sep 19, 2020
Embed
What would you like to do?
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