Skip to content

Instantly share code, notes, and snippets.

@w0rm
Created June 12, 2017 05:38
Show Gist options
  • Save w0rm/9811276a76b42e06aadba160d676c836 to your computer and use it in GitHub Desktop.
Save w0rm/9811276a76b42e06aadba160d676c836 to your computer and use it in GitHub Desktop.
Check for the Internet connection
#!/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