Skip to content

Instantly share code, notes, and snippets.

@jordanst3wart
Last active February 27, 2021 01:35
Show Gist options
  • Save jordanst3wart/05b1d30b29a9da1577ddc8c7544c15f9 to your computer and use it in GitHub Desktop.
Save jordanst3wart/05b1d30b29a9da1577ddc8c7544c15f9 to your computer and use it in GitHub Desktop.
Test if the network is down
#!/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