Tutorial How to automatically run a script on asus routers that monitors your WAN link - will reboot the router if WAN is down. (from POV of a non linux guy)

  • ATTENTION! As of November 1, 2020, you are not able to reply to threads 6 months after the thread is opened if there are more than 500 posts in the thread.
    Threads will not be locked, so posts may still be edited by their authors.
    Just start a new thread on the topic to post if you get an error message when trying to reply to a thread.

Carme

New Around Here
My hardware Asus RT-AX92U, I believe this may work for many other asus routers but I only have the RT-AX92U router so I cannot say if this works for other asus routers.
Firmware 3.0.04.386.43084

Note: You need a USB stick to automate.

First my issue and why I wanted to automate a reboot of the router.

The issue I have with the RT-AX92U is that I see the error 'WAN Connection: ISP's DHCP did not function properly.' in the System log of the router every few days, from that moment I seem to experience that the wan traffic starts to slow to a crawl and finally after a while 30-60 minutes stops completely. I have played with the 'dhcp query frequency', tried all the options no difference. I suspect it has nothing to do with dhcp, just that is the error that appears when the WAN stops working. Let us one day hope that firmware will fix our woes on asus routers; but I also hope for world peace and we all know how that is going.

Trouble shooting.

-I have two diffent ISP's, router does the same thing (Virginmedia and BT), so it is not an isp thing.
-I have RMA the RT-AX92U and the same thing happens with a brand new router they sent (something bad with the firmware perhaps) and no I'm not playing with finding an old firmware that does not have this specific issue- they all have some issue or other. :)
-I have factory reset after upgrading the firmware many times, powered off many times, it has nothing to do with any settings per se, pretty much use everything at default straight out of the box, same issue after a few days.

So what can we do? Well, when I experience this issue, it is simply fixed by powering off the router and then powering it back on again, takes under a minute for a power off /on and to be fully fixed. So let us work on automating this manual reboot; not being a linux/unix guy I struggled at first to get this working, so here are the steps I took, hoping these steps help other users who may like myself also not be linux savvy. Credit to the guys who create and post helpful information, few names at the end of this post.

Automate a wan reboot script.

1) Someone has kindly done all the work in scripting / testing wan is up, if not then reboot your router. Read the instructions and get the files here:


Note: Do not copy and then paste the script into a new file from github to a windows operating system -that will not work as you created it on a windows OS, its so much easier to download the file on git, use that, do not open/edit in a windows OS, it may save to a format the router os might not like.

To be clear on how to download from github, if your not familiar with github, goto the url https://github.com/MartineauUK/Chk-WAN, click on the green 'Code' button, a drop down menu appears, at the bottom after clicking you see the option to download as a ZIP, download and extract to where you see fit, I used c:\temp\trans (I'll use this location for future examples below). You only need to extract 'chkWAN.sh' to c:\temp\trans.

2) Go download putty and install from here:


I downloaded the 64-bit x86: putty-64bit-0.76-installer.msi as I have 64bit windows 11 beta.

3) Go download pscp.exe (I found it easier to transfer a file from windows to router with pscp, but use whatever you know).
Download from the same place as putty, the pscp.exe is down the page a little bit under the putty options, I downloaded 64-bit x86: pscp.exe Copy it to c:\temp\trans

4) Log in to your router from your pc web browser, I use router.asus.com or whatever the ip address is, log in. Goto 'Administration', 'System', then scroll down to 'Service' or where you see the 'Enable SSH' option, enable it, do not use port 22, do what it suggests pick a port number between 1025-65535, you will need the port number in a bit so record it. Make sure Allow password login is set to 'yes'. I guess you can switch ssh back off after you get this working if needed.

5) You need a USB stick, I had an old 4gb one lying around so used that. I formatted it to fat in windows i.e. open file explorer FIRST, insert USB to your pc, make sure you see and you know what new drive letter appeared, double check there is nothing on the usb stick you need. Once formatted (right click drive letter in windows, choose format), I inserted it to the far right slot (not sure it matters) on my RT-AX92U.

6) Open putty as an admin (just to sure, as it might write cert keys to registry), make sure you're clicked on 'session' from the left menu, add in your router address or ip address (should be router.asus.com), change the port to the port number you picked earlier, defaults to 22, change this. Click 'open'. A new command prompt box opens. In that box, type you're 'Admin' user name for your router, press enter, type your password, press enter. You should see something like:

[email protected]:/tmp/home/root#

7) Ensure your USB stick inserted to your router. Copy and paste into putty these three lines, do not rename the folder from jffs, I believe it has to be this folder name (I could be wrong but it does not matter, leave it jffs):

nvram set script_usbmount="touch /jffs/success"
nvram commit
service reboot

Run these three lines together or one at a time in putty. Your asus router reboots, close putty, when the router comes back, log back into putty, check the router still see's the folder on the USB you created called jffs to do this, after a reboot. Type:

ls -l /jffs/success

You should see something like:

-rw-rw-rw- 1 xxAdminxx root 0 Aug 21 11:29 /jffs/success
[email protected]:/tmp/home/root#

8) Open a command prompt as admin or powershell or windows terminal they all should work, navigate to c:\temp\trans ( type 'cd c:\temp\trans' no quotes ). Edit and paste the following to the cmd prompt which should be pointed to c:\temp\trans.

pscp -P 1025 -scp C:\temp\Trans\chkWAN.sh [email protected]:/jffs/chkWAN.sh

Enter your password, the file should copy to your jffs folder on your router(USB). Go back to putty type cd /jffs then type ls, check to see if chkWAN.sh comes up as a file, if it did, you copied it successfully.

Now change chkWAN.sh permissions so it can be run/executed - in putty type:

cd /jffs

to get to the jffs folder, then type:

chmod a+x chkWAN.sh

This changes the permissions of the newly copied file.

9) Setup for automatic running of chkWAN.sh. From putty type:

nvram set script_usbmount="/jffs/chkWAN.sh"

The file will now run on a reboot.

That is it, test the file runs, watch what it does, just by typing:

./chkWAN.sh

You see it running in putty, to stop via putty type:

./chkWAN.sh stop

Go check the authors instructions/document for chkWAN cmd usage (but note its now fully automated and running on your router). https://github.com/MartineauUK/Chk-WAN

10) chkWAN.sh creates logs into your system log on your router, so you can see what its doing. Test it out by unplugging your wan connection, then watch and see the router reboot itself after a minute or so. Then when its back, check the system log, to see what it did, example:

Working fine, router log shows:

(chkWAN.sh): 2313 Monitoring connection OK.....(Successful ping to '9.9.9.9'). Will check again in 30 secs

I pulled my wan connection cable, this is what I saw in the router log, and the router did reboot itself.

--
kernel: eth0 (Int switch port: 3) (Logical Port: 3) (phyId: c) Link DOWN.
WAN Connection: ISP's DHCP did not function properly.
WAN Connection: WAN(0) link down.
(chkWAN.sh): 2313 v1.17 Monitoring connection using PING method to 9.9.9.9 check FAILED
(chkWAN.sh): 2313 v1.17 Monitoring connection using PING method to 1.1.1.1 check FAILED
(chkWAN.sh): 2313 Monitoring pass 2 out of 3
(chkWAN.sh): 2313 v1.17 Monitoring connection using PING method to 9.9.9.9 check FAILED
(chkWAN.sh): 2313 v1.17 Monitoring connection using PING method to 1.1.1.1 check FAILED
(chkWAN.sh): 2313 Monitoring pass 3 out of 3
(chkWAN.sh): 2313 v1.17 Monitoring connection using PING method to 9.9.9.9 check FAILED
(chkWAN.sh): 2313 v1.17 Monitoring connection using PING method to 1.1.1.1 check FAILED
(chkWAN.sh): 2313 Rebooting..... (Action=REBOOT)
rc_service: service 11843:notify_rc start_reboot
--

Note: You have to leave the USB stick plugged to your router, all the time.

Credits

I take no credit for the script/files/apps - just want to thank MartineauUK / steve288 / bbunge & ColinTaylor - I scraped their forum threads/cmds/git into a simple list I could use being as I am not a linux guy. MartineauUK seems a genuis :) kudos.

Hope this helps someone like me, who is not familiar with linux terms install and get this running, happy asus routering, over and out, see you on the wan side.

Thanks

Carme
 
Last edited:

empiretc

Occasional Visitor
Thanks for this awesome post!! Everything was straight forward and worked great except for this command:

pscp -P 1025 -scp C:\temp\Trans\chkWAN.sh [email protected]:/jffs/chkWAN.sh

had to change " [email protected]" to what was displayed in putty in order for it to successfully connect. no changes were made to the script at all.

The router log shows: "(chkWAN.sh): 2394 Monitoring connection OK.....(Successful ping to '9.9.9.9'). Will check again in 30 secs"

We really like this router, but have been dealing with this connection loss issue since getting it in May. SO many different things have been tried, but nothing has worked. We would always have to reboot it to restore the internet connection. Hopefully, this solves our issue for good.

Thanks again for this post!!!!
 

Martineau

Part of the Furniture
The router log shows: "(chkWAN.sh): 2394 Monitoring connection OK.....(Successful ping to '9.9.9.9'). Will check again in 30 secs"

We really like this router, but have been dealing with this connection loss issue since getting it in May. Hopefully, this solves our issue for good.
Just to clarify, my script may prove to be a beneficial timely workaround, but it is definitely NOT the absolute solution for the (still as yet unidentified) underlying poor stability of your WAN connection.
 

empiretc

Occasional Visitor
Just to clarify, my script may prove to be a beneficial timely workaround, but it is definitely NOT the absolute solution for the (still as yet unidentified) underlying poor stability of your WAN connection.

Agreed. Hopefully Asus can get their act together and release a more stable firmware. This was never an issue with the Linksys EA8300 that this router replaced. Was really hoping to get Merlin for the RT-AX92U, but it does not seem like that is going to happen.

Since installing your script, we have run some basic tests and it has functioned absolutely perfectly. Thank you for all your hard work on this, and we truly hope this takes care of things because it has been a serious issue especially when working remotely.

Thanks again.
 

bbunge

Part of the Furniture
Much easier to use WinSCP to do the editing. You will still need Putty.
 

Latest threads

Sign Up For SNBForums Daily Digest

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