What's new

[beta] Dual WAN helper script (discontinued)

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

thelonelycoder

Part of the Furniture
This originated in this thread.

December 23 2018
The Dual WAN helper script is no longer available to download. See this post for details.

dual-wan-helper is a script that continuously runs in the background once triggered by wan-start and pings a set domain. When ping fails it will restart the wan_service.
It can send a notification email when enabled of the WAN type change with additional info.

Apart from the email credentials and server settings, all script parameters are taken from the WAN/Dual WAN page in the router WebUI.
It tries to use these parameters to only take action when necessary.

Read the "How to use this script" part at the top of the file.

Let's see where this goes, should work best with ASUSWRT-Merlin 380.67 because in this version Dual WAN appears to work best, but other versions might work too.

Note that John's LTS fork and older Merlin versions are a bit sketchy with switching Primary to Secondary WAN but eventually will with this script.
As always, ideas, suggestions and improvements are very welcome.

Download from the website in section Other scripts
 
Last edited:
@thelonelycoder wow that sounds interesting. But i still have some questions before testing.
1. Does it work together with asus dual wan script or it blocks it and does all the business?
2. Does it help to fix that wan1-wan2-wan1-wan2 constant switch when primary wan is down but watchdog still switches back to primary within timeout set?
3. Does it fully use the code and features from the latest email notification script that is perfect i would say!
4. What does "When ping fails it will restart the wan_service" mean? is it the only function? What extra functionality or comfort does it give? I don't quite understand this point. Could you please explain a little more what this script does. And how does it help asus' dual wan script.
5. Running latest Merlin i noticed that router still tries to switch to primary even if primary is not powered. Sometimes it happends once per hour, sometimes 10 times per hour..

Thank you very much you are doing a huge job!
 
1. Does it work together with asus dual wan script or it blocks it and does all the business?
This is meant to replace it, so don't run both of them at the same time.
2. Does it help to fix that wan1-wan2-wan1-wan2 constant switch when primary wan is down but watchdog still switches back to primary within timeout set?
I cannot suppress that stupid behavior of stupid WAN type switching to determine if the primary wan is up. The only way to prevent this is to NOT set "Allow failback". It will stay then on the working WAN type until it fails.
3. Does it fully use the code and features from the latest email notification script that is perfect i would say!
Except the reboot option, everything essential is built in this beta version.
4. What does "When ping fails it will restart the wan_service" mean? is it the only function? What extra functionality or comfort does it give? I don't quite understand this point. Could you please explain a little more what this script does. And how does it help asus' dual wan script.
It tries to be smart when to restart WAN using the set parameters in the WebUI.
It also always knows which WAN type is currently in use.
Instead of auto-running it through the wan-start script, you can manually start it by running:
Code:
/jffs/scripts/dual-wan-helper
You see then the verbose output and what it will do next.
WAN type and IP in use is 100% correct with this script, which was not always the case with the wan_connect_notification script.
When using the verbose (manual) mode, you best set the SEND_MAIL to off, a bit more output is then generated to say what it does.
5. Running latest Merlin i noticed that router still tries to switch to primary even if primary is not powered. Sometimes it happends once per hour, sometimes 10 times per hour..
Again, this is outside of what a shell script can do. But the determining parameter is "Failback Execution Time", which is an added up time from the other parameters.
The higher this is, the less auto-back switching happens to check if Primary WAN has come back up.
 
Last edited:
This is meant to replace it, so don't run both of them at the same time.
So dual wan should be disabled in settings? Or this script does all the job and i leave dual wan settings on? As soon as i disable dual wan - all the dual wan settings disappear.

The only way to prevent this is to NOT set "Allow failback". It will stay then on the working WAN type until it fails.
That is not cool at all. Especially when secondary is limited 4G connection. Stupid Assus.

Except the reboot option, everything essential is built in this beta version.
As far as i understand - there are no user set timeouts anymore for ip, NTP detection and so on - so script detects all the timeouts on its own without manual settings. Right?

It tries to be smart when to restart WAN using the set parameters in the WebUI.
I still don't get the difference between this script and asus' dual wan script. May be i am missing something but on latest Merlin asus' script started to switch to secondary wan even when primary wan is just not pingable. So it works much better and almost like it should. If your script makes it work even better - that's great!

But the determining parameter is "Failback Execution Time", which is an added up time from the other parameters.
No i think problem is not with failback ececution time. Because when running previous firmwares i could unplug primary wan - and router stayed on secondary wan forever. Now it tries to switch to primary without any logic explanation. Sometimes within 5 minutes, sometimes it can stay on secondary for several hours. I think there is a bug in asus script and as soon as secondary 4g connection freezes for some time - router forces switching to primary even though primary is unplugged. Thats' only my guess because it's the only way i can explain that switching happends within different time periods.
 
@stylish_me Don't disable Dual WAN, this is a helper script to the Dual WAN feature set in the UI.
It's function is simple: Restart WAN if the other WAN type does not come up when it should.

I have removed all user settings pertaining to when and what to do so these do not interfere with what is set through the UI.
This script is driven by these UI settings and supports them, in a helping way if Asus fails to do it's job.
No i think problem is not with failback ececution time. Because when running previous firmwares i could unplug primary wan - and router stayed on secondary wan forever. Now it tries to switch to primary without any logic explanation. Sometimes within 5 minutes, sometimes it can stay on secondary for several hours. I think there is a bug in asus script and as soon as secondary 4g connection freezes for some time - router forces switching to primary even though primary is unplugged. Thats' only my guess because it's the only way i can explain that switching happends within different time periods.
Look again at the settings I have posted above, in 380.67 this works like a charm.
You can increase "Detect interval" and "Failover execution time" to lower the switching back to Primary WAN.
 
I have removed all user settings pertaining to when and what to do so these do not interfere with what is set through the UI.
I am speaking about several timeout settings that were in email notification script. They are removed as well, right? So script calculates all the timeouts to detect NTP, current ip and so on itself without any user set timeouts.
 
I am speaking about several timeout settings that were in email notification script. They are removed as well, right? So script calculates all the timeouts to detect NTP, current ip and so on itself without any user set timeouts.
Exactly. It tries to be smart about it.
 
Look again at the settings I have posted above, in 380.67 this works like a charm.
i wouldn't say that these settings can work like a charm because it means that failback will happen every 24 seconds even if primary wan is still down. So you will get email notifications and have no internet every 24 seconds...
And if you are right saying that this failback timeout works even when primary is unplugged - it means that absolutely every time when primary is down, unplugged or unpingable - you will get this wan1-wan2-wan1 cycle every 24 seconds.
 
i wouldn't say that these settings can work like a charm because it means that failback will happen every 24 seconds even if primary wan is still down. So you will get email notifications and have no internet every 24 seconds...
And if you are right saying that this failback timeout works even when primary is unplugged - it means that absolutely every time when primary is down, unplugged or unpingable - you will get this wan1-wan2-wan1 cycle every 24 seconds.
It only notifies you of a WAN change if it actually changed it. The fckn Asus probing does not qualify as a change.
Test it, you'll see.
 
It only notifies you of a WAN change if it actually changed it. The fckn Asus probing does not qualify as a change.
Wow i like how it sounds. Will do the tests for sure. But it means that i will not have internet within that wan1-wan0-wan1 cycle (minimum 8 seconds with your settings) and the router will not notify me about it.

I cannot suppress that stupid behavior of stupid WAN type switching to determine if the primary wan is up. The only way to prevent this is to NOT set "Allow failback". It will stay then on the working WAN type until it fails.

It seems that you are not right. Or i am not right. lol. Now running latest Merlin i have a setting "Continous detect Primary WAN successfully over 99 times ( = 891 sec.)"
And router turns to primary every 891 second. But according to the name of this setting - router should constantly ping 8.8.8.8 within that 891 second time. Either Asus cheats and 891 seconds is just a timeout to switch to primary, make ping and switch back to secondary if primary is unpingable. Or i see no use of calling that setting so.
And i have an idea. With your even numbers maximum failback time is 784 sec. And it is not too much. May be you can make a setting for your script to multiply this number to 2,3,4 and so on times. To make this failback time at least 1 hour. I think if router switches back to primary once per hour - is quite ok. OR. You can make this failback time customizable through script's settings. That would be perfect. Because i think 2-4 seconds is enought to ping primary wan. But if you use 2 sec as detect interval - so failback timer will be only 196sec which is too short.
 
@thelonelycoder hi
just installed the script but i don't see it running. Made all the changes, turned on mail notification, but no letters in my inbox and nothing about this script in logs.
OR it shouldn't send anything when router reboots??
When i try to run it via terminal - i get in logs:
"Aug 1 12:16:58 admin: dual-wan-helper: Prevented second instance of this script, lockfile exists. via /jffs/scripts/dual-wan-helper
"
So as far as i understand this script doesn't send emails when router reboots. And i think it should )
 
Last edited:
@thelonelycoder hi
just installed the script but i don't see it running. Made all the changes, turned on mail notification, but no letters in my inbox and nothing about this script in logs.
OR it shouldn't send anything when router reboots??
Make sure you changed the line in wan-start and set the new script as executable.
It will send one mail per WAN type change, including one when booting.
 
Make sure you changed the line in wan-start and set the new script as executable.
Changed to on and the script is 0755

It will send one mail per WAN type change, including one when booting.
Just unplugged lan cable - router reconnected to secondary wan, still no email notification. I see
Aug 1 12:19:48 admin: dual-wan-helper: Prevented second instance of this script, lockfile exists. via /jffs/scripts/dual-wan-helper
two times after
Aug 1 12:19:35 WAN(0)_Connection: WAN was exceptionally disconnected.
happened.

Now
Aug 1 12:20:47 WAN(1)_Connection: WAN was restored.
but still no email. All the email settings are correct, i copie them line by line from email notification script.
 
Run it in verbose mode and see what it tells you when the WAN type changes.
It'll say "WAN type change on (date)".
Code:
/jffs/scripts/dual-wan-helper kill
then
Code:
/jffs/scripts/dual-wan-helper
Unplug cable and wait for message.
 
Run it in verbose mode

/jffs/scripts$ /jffs/scripts/dual-wan-helper kill
Terminated
/jffs/scripts$ /jffs/scripts/dual-wan-helper
Primary-WAN reported
ping OK, Primary-WAN, 10.13.70.222, WAN test in 792
ping OK, Primary-WAN, 10.13.70.222, WAN test in 784
ping OK, Primary-WAN, 10.13.70.222, WAN test in 776
ping OK, Primary-WAN, 10.13.70.222, WAN test in 768
ping OK, Primary-WAN, 10.13.70.222, WAN test in 760
ping NOK, timeout in 24
Secondary-WAN reported
ping: sendto: Network is unreachable
ping NOK, timeout in 16
ping OK, Secondary-WAN, 192.168.0.111, WAN test in 776
ping OK, Secondary-WAN, 192.168.0.111, WAN test in 768
ping OK, Secondary-WAN, 192.168.0.111, WAN test in 760


and still
Aug 1 12:35:59 admin: dual-wan-helper: Prevented second instance of this script, lockfile exists. via /jffs/scripts/dual-wan-helper

before
Aug 1 12:36:58 WAN(1)_Connection: WAN was restored.
 
/jffs/scripts$ /jffs/scripts/dual-wan-helper kill
Terminated
/jffs/scripts$ /jffs/scripts/dual-wan-helper
Primary-WAN reported
ping OK, Primary-WAN, 10.13.70.222, WAN test in 792
ping OK, Primary-WAN, 10.13.70.222, WAN test in 784
ping OK, Primary-WAN, 10.13.70.222, WAN test in 776
ping OK, Primary-WAN, 10.13.70.222, WAN test in 768
ping OK, Primary-WAN, 10.13.70.222, WAN test in 760
ping NOK, timeout in 24
Secondary-WAN reported
ping: sendto: Network is unreachable
ping NOK, timeout in 16
ping OK, Secondary-WAN, 192.168.0.111, WAN test in 776
ping OK, Secondary-WAN, 192.168.0.111, WAN test in 768
ping OK, Secondary-WAN, 192.168.0.111, WAN test in 760


and still
Aug 1 12:35:59 admin: dual-wan-helper: Prevented second instance of this script, lockfile exists. via /jffs/scripts/dual-wan-helper

before
Aug 1 12:36:58 WAN(1)_Connection: WAN was restored.
I see where it fails in your case. Let me change that.
I'll post a new version as soon as possible.
 
I see where it fails in your case. Let me change that.
Could you please highlight the part of the code you change - not to make all the settings from the very beginning. Thanx!

And one more interesting point:

ping OK, Secondary-WAN, 192.168.0.111, WAN test in 368
ping OK, Secondary-WAN, 192.168.0.111, WAN test in 360
ping OK, Secondary-WAN, 192.168.0.111, WAN test in 352
ping OK, Secondary-WAN, 192.168.0.111, WAN test in 344
ping OK, Secondary-WAN, 192.168.0.111, WAN test in 336
ping NOK, timeout in 24
ping NOK, timeout in 16
Primary-WAN reported
ping OK, Primary-WAN, 10.13.70.222, WAN test in 776
ping OK, Primary-WAN, 10.13.70.222, WAN test in 768
ping OK, Primary-WAN, 10.13.70.222, WAN test in 760
ping OK, Primary-WAN, 10.13.70.222, WAN test in 752

So even being on secondary wan it still pings this connection through 4g router instead of waiting for failback time. And if 4g drops for some seconds - it switches back to primary wan before timeout. It is ok when primary wan is ok but when primary is down - so no connection at all.
And it starts ping timeout again after switching back to primary wan. I think that is not right. 784 (98x8) seconds are only for failback, not for failover.. Failover is set to 2x8 = 16 sec.
 
ping OK, Primary-WAN, 10.13.70.222, WAN test in 776
................
ping OK, Primary-WAN, 10.13.70.222, WAN test in 64
ping OK, Primary-WAN, 10.13.70.222, WAN test in 56
ping OK, Primary-WAN, 10.13.70.222, WAN test in 48
ping OK, Primary-WAN, 10.13.70.222, WAN test in 40
ping OK, Primary-WAN, 10.13.70.222, WAN test in 32
ping OK, Primary-WAN, 10.13.70.222, WAN test in 24
ping OK, Primary-WAN, 10.13.70.222, WAN test in 16
ping OK, Primary-WAN, 10.13.70.222, WAN test in 8

WAN type change on Tue, 01 Aug 2017 12:57:13 +0300
WAN type = Primary-WAN

sending WAN change mail, WAN type = Primary-WAN

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 428 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0100 428 0 0 100 428 0 179 0:00:02 0:00:02 --:--:-- 181
ping OK, Primary-WAN, 10.13.70.222, WAN test in 792
ping OK, Primary-WAN, 10.13.70.222, WAN test in 784


Anly after that i got an email and saw this:
Aug 1 12:57:13 admin: dual-wan-helper: WAN type change detected, WAN type = Primary-WAN, via /jffs/scripts/dual-wan-helper
Aug 1 12:57:16 admin: dual-wan-helper: WAN type change detected, notification sent to avoronkov@gmail.com via /jffs/scripts/dual-wan-helper
 
ping OK, Secondary-WAN, 192.168.0.111, WAN test in 336
ping NOK, timeout in 24
ping NOK, timeout in 16
Primary-WAN reported
ping OK, Primary-WAN, 10.13.70.222, WAN test in 776
ping OK, Primary-WAN, 10.13.70.222, WAN test in 768
That is Asus switching back, the timeout is the wait time until WAN is restarted. Unless ping is successful with whichever WAN type.

This intended so it does not restart WAN or send WAN change mail unless it needs to.
 
Anly after that i got an email and saw this:
Aug 1 12:57:13 admin: dual-wan-helper: WAN type change detected, WAN type = Primary-WAN, via /jffs/scripts/dual-wan-helper
Aug 1 12:57:16 admin: dual-wan-helper: WAN type change detected, notification sent to avoronkov@gmail.com via /jffs/scripts/dual-wan-helper
That's what I'm changing now. The high count prevents the WAN type change email for a long time until it reaches 0.
 

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!

Staff online

Top