Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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

This comment has been minimized.

Show comment Hide comment
@ninadpchaudhari

ninadpchaudhari Jul 23, 2015

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 !

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 !

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