Created
June 12, 2017 05:38
-
-
Save w0rm/9811276a76b42e06aadba160d676c836 to your computer and use it in GitHub Desktop.
Check for the Internet connection
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 | |
# Usage: HOST=public_gateway_ip_here ./internet.sh | |
CONNECTED=30 | |
DISCONNECTED=0 | |
INTERVAL=$DISCONNECTED | |
while sleep $INTERVAL | |
do | |
LOSS=$(ping -c 10 -s 14 $HOST|grep packet|awk '{print $7}'|cut -d'.' -f1) | |
echo "$LOSS packets lost" | |
if [ 50 -ge $LOSS ] | |
then | |
if [ $DISCONNECTED -eq $INTERVAL ] | |
then | |
say "Internet Connected" | |
INTERVAL=$CONNECTED | |
fi | |
else | |
if [ $CONNECTED -eq $INTERVAL ] | |
then | |
say "Internet Lost" | |
INTERVAL=$DISCONNECTED | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment