This is part 3 of 3… See the first post here.
In the first post of this series, I posted a script to login to the router’s web management page. The second post detailed the script that checks the status of each WAN connection. The script below will refresh the WAN connections as needed.
This script depends on the second script “wan_status.sh”, they should be placed in the same directory. This is the script to call to initiate a full check/refresh cycle.
At a prompt or via cron, you run this script: wan_refresh.sh
$ ./wan_refresh.sh
wan_refresh.sh sources wan_status.sh which sources login.sh
This script assumes two WAN connections. If you have more or less, you’ll have to make the appropriate changes. We use Google’s public DNS servers for the ping tests. This script alternates between the two, which is essential for this to work.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#!/bin/bash cd $(cd $(dirname $0); pwd -P) source wan_status.sh if [[ $wan1status = "DOWN" ]] then if [[ $wan1dns = "8.8.8.8" ]] then dns="8.8.4.4" else dns="8.8.8.8" fi echo "`date`: Refreshing WAN1">>wan_refresh.log refresh=$(wget --timeout=7 -qO- --load-cookies cookies.txt --save-cookies cookies.txt --keep-session-cookies "http://$ROUTER_IP/userRpm/DiagnosticOnline.htm?rd_wan=0&rd_enable=1&rd_auto=0&ping_dst_ip=$dns&dns_dst_ip=$dns&rd_enable_sec=0&btn_save=Save") else echo "`date`: WAN1 UP">>wan_refresh.log fi if [[ $wan2status = "DOWN" ]] then if [[ $wan2dns = "8.8.8.8" ]] then dns="8.8.4.4" else dns="8.8.8.8" fi echo "`date`: Refreshing WAN2">>wan_refresh.log refresh=$(wget --timeout=7 -qO- --load-cookies cookies.txt --save-cookies cookies.txt --keep-session-cookies "http://$ROUTER_IP/userRpm/DiagnosticOnline.htm?rd_wan=1&rd_enable=1&rd_auto=0&ping_dst_ip=$dns&dns_dst_ip=$dns&rd_enable_sec=0&btn_save=Save") else echo "`date`: WAN2 UP">>wan_refresh.log fi |