Last active
February 27, 2021 01:35
-
-
Save jordanst3wart/05b1d30b29a9da1577ddc8c7544c15f9 to your computer and use it in GitHub Desktop.
Test if the network is 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 | |
path="/tmp" # /home/pi/Documents | |
if [ -f "$path/pid.txt" ]; then | |
echo "pid file found. Exiting..." | |
exit 0 | |
fi | |
echo "running" > "$path/pid.txt" | |
check_connection(){ | |
dots="$1" | |
wget -q --tries=5 --timeout=5 --spider https://dns.google/ > /dev/null | |
retval=$? | |
if [[ $retval -ne 0 ]]; then | |
wget -q --tries=5 --timeout=5 --spider https://1.1.1.1/ > /dev/null | |
retval=$? | |
if [[ $retval -ne 0 ]]; then | |
wget -q --tries=5 --timeout=5 --spider https://www.facebook.com/ > /dev/null | |
retval=$? | |
if [[ $retval -ne 0 ]]; then | |
echo "[$(date)] Offline$dots" >> "$path/offline-time.txt" | |
sleep 5 | |
check_connection ".$dots" | |
fi | |
fi | |
fi | |
} | |
check_connection "" | |
rm -f "$path/pid.txt" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment