Created
August 9, 2017 01:55
-
-
Save adamf/7317523e97b929db0a63a8bf34ea0814 to your computer and use it in GitHub Desktop.
A script to track when my internet goes up and down
This file contains hidden or 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 | |
set -x | |
SERVERIP=8.8.8.8 | |
LOGFILE=pings.txt | |
STATE=U | |
END=5000000 | |
for ((i=1;i<=END;i++)); do | |
foo=`date` | |
ping -c 1 $SERVERIP > /dev/null 2>&1 | |
result=$? | |
if [ $result -ne 0 ]; then | |
if [ "$STATE" != "D" ]; then | |
echo "$foo Can't connect to ${SERVERIP}" >> $LOGFILE | |
STATE=D | |
fi | |
else | |
if [ "$STATE" != "C" ]; then | |
echo "$foo Connected to ${SERVERIP}" >> $LOGFILE | |
STATE=C | |
fi | |
fi | |
sleep 10 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment