Created
April 22, 2020 22:34
-
-
Save Leo-PL/9e12e33999eb97d8c1b8043307c3c216 to your computer and use it in GitHub Desktop.
Simple WAN watchdog for OpenWrt with LTE modem. Add to crontab.
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/sh | |
USB_GPIO=21 | |
DELAY=1 | |
gpio_value="/sys/class/gpio/gpio${USB_GPIO}/value" | |
echo 0 > ${gpio_value} | |
sleep ${DELAY} | |
echo 1 > ${gpio_value} |
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/sh | |
HOSTS="8.8.8.8 8.8.4.4 1.1.1.1 1.0.0.1" | |
PING_WAIT=2 | |
SLEEP_TIME=5 | |
NETWORK="wan" | |
tries=0 | |
while [[ $tries -lt 10 ]] | |
do | |
for host in ${HOSTS} | |
do | |
if /bin/ping -c 1 -W ${PING_WAIT} ${host} >/dev/null | |
then | |
exit 0 | |
fi | |
done | |
tries=$((tries+1)) | |
done | |
logger Ping watchdog triggered, restarting modem | |
ifdown ${NETWORK} | |
sleep ${SLEEP_TIME} | |
./reset_modem_hard.sh | |
sleep ${SLEEP_TIME} | |
ifup ${NETWORK} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment