Skip to content

Instantly share code, notes, and snippets.

@navhaxs
Created February 11, 2015 21:33
Show Gist options
  • Save navhaxs/8029bea3420cdbb11047 to your computer and use it in GitHub Desktop.
Save navhaxs/8029bea3420cdbb11047 to your computer and use it in GitHub Desktop.
openwrt wan auto reconnect hotplug script
# Place me in /etc/hotplug.d/iface/99-keepwanalive
if [ "$ACTION" = "ifdown" -a "$INTERFACE" = "wan" ]; then
COUNTER=0
PASS=0
while [ $PASS -eq 0 ]
do
grep "up" /sys/class/net/eth0/operstate > /dev/null
if [ $? != "up" ]; then
let COUNTER++
logger -t DEBUG "Attempt #${COUNTER} to reconnect wan"
ifup wan
sleep 15 #sec
else
PASS=1
fi
done
fi
@ninadpchaudhari
Copy link

Great idea !
much better than those using pings and corn jobs !
Just that there are a few mistakes ...
This one goes to infinite loop .
as "ifup wan" takes wan down and then again up , if wan is already up, the wan connection redials every 15 seconds !
also, /sys/class/net/eth0/operstate needs to be set to appropriate interface , depending on each user
Have corrected the same , available here : https://gist.github.com/ninadpchaudhari/6561841ffc3667b1e5ee

I dont think merge request can be sent to Gists !

@ThomasCr
Copy link

ThomasCr commented Jul 5, 2018

maybe just set once "ifup wan" without while loop and all other things...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment