Scripted updated: 2022-03-14
I reformat, can you pls check if this is correct.
First create the script, called /root/wan-watchdog.sh
cat << "EOF" > /root/wan-watchdog.sh
#!/bin/sh
. /lib/functions/network.sh
network_flush_cache
network_find_wan NET_IF
network_get_gateway NET_GW "${NET_IF}"
TRIES="0"
while [ "${TRIES}" -lt 5 ]
do
if ping -w 3 "${NET_GW}" &> /dev/null
then exit 0
else let TRIES++
fi
done
echo 0 > /sys/class/gpio/usb_power/value
sleep 1
echo 1 > /sys/class/gpio/usb_power/value
EOF
chmod +x /root/wan-watchdog.sh
then, add it to scheduled task (cron) and execute this every minute. You can change the number to 2 (every two minutes) etc.
cat << "EOF" >> /etc/crontabs/root
*/1 * * * * /root/wan-watchdog.sh
EOF
Sorry I didn’t test this.