What's new

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)

  • 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!

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:

xxAdminxx@RT-AX92U-3700:/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
xxAdminxx@RT-AX92U-3700:/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 xxAdminxx@router.asus.com:/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:
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 xxAdminxx@router.asus.com:/jffs/chkWAN.sh

had to change " xxAdminxx@router.asus.com" 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!!!!
 
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.
 
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.
 
Much easier to use WinSCP to do the editing. You will still need Putty.
 
I got a similar issue with my RT-AX92U (WAN down in a few day) and I am trying to install the ChkWAN.sh according to the instruction on GitHub.
Can you explain why do we need to use an USB drive install of just having the script to be load from the router itself?
I tried to create a script "./jffs/scripts/wan-start" but it seems not being executed each time I restart the router.

--- EDIT ---
I figured out why and the usb is mainly to trigger the usb mount script to run. In fact the script can be placed in the router memory instead of usb but you still need to have the usb mount event to trigger the script. Thanks for the tutorial.
 
Last edited:
Perhaps a dumb question, but from a long suffering ASUS RT-AX92U user who reboots at least twice a week to correct loss of WAN IP...

Is there a Macintosh version of these instructions? I believe we dont use PUTTY and can do most of not all of the steps from Terminal, but it would be great if someone who has done it already could walk me through. Thanks
 
Perhaps a dumb question, but from a long suffering ASUS RT-AX92U user who reboots at least twice a week to correct loss of WAN IP...

Is there a Macintosh version of these instructions? I believe we dont use PUTTY and can do most of not all of the steps from Terminal, but it would be great if someone who has done it already could walk me through. Thanks

same stuff...

 
On a Mac, you can do all the remote commands (ssh / scp) from Terminal without installing new software - it's built in.
 
On a Mac, you can do all the remote commands (ssh / scp) from Terminal without installing new software - it's built in.
Thanks - that is what I suspected but was looking for confirmation. I waiting for next crash and then will install.
 
Any idea why this keep failing?
Is being executed in Windows from Putty as an Administrator exactly as the instructions above. Even downloaded WinWCP and still no luck.

C:\tmp>pscp -P 1055 -scp c:\tmp\ChkWAN.sh Admin@router.asus.com:/jffs/ChkWAN.sh
Admin@router.asus.com's password:
sh: scp: not found
FATAL ERROR: Received unexpected end-of-file from server
 
 
Thanks.
Brought by AC66U back online and used WinSCP to transfer the file over to the USB plugged into it. Unmounted and plugged it into my AX86U and then cp the file from USB stick /mnt/JFFS to /JFFS
 
A caveat before I start in that I should have posted my question and used the power of the community to source the answer - my bad. Being a newbie I asked the question directly and was tapped on the wrist and alerted to the protocol - a learning moment. Now with that out of the way, I asked @Martineau about the potential to enter a boot loop in the event that the ISP is truly down and not coming back up if the script is blindly launched from init_start or via cron without checking the wan connection first. Here is the reply:

"if you have configured ChkWAN to REBOOT in the event of a failure, then the script will do as instructed = potentially forever.

So after a REBOOT, the script should be configured such that it only starts to monitor the WAN state AFTER the first successful WAN connection.

i.e. it isn't wise to blindly schedule the script from say init-start (either by using the delay parameter or either a static/dynamic cron schedule) but instead schedule the script from the WAN 'connected' event to prevent the possibly inconvenient REBOOT loop cycle if the WAN never ever recovers after a REBOOT."

For reference: https://github.com/RMerl/asuswrt-merlin.ng/wiki/User-scripts#wan-event
 
Last edited:
A caveat before I start in that I should have posted my question and used the power of the community to source the answer - my bad. Being a newbie I asked the question directly and was tapped on the wrist and alerted to the protocol - a learning moment. Now with that out of the way, I asked @Martineau about the potential to enter a boot loop in the event that the ISP is truly down and not coming back up if the script is blindly launched from init_start or via cron without checking the wan connection first. Here is the reply:

"if you have configured ChkWAN to REBOOT in the event of a failure, then the script will do as instructed = potentially forever.

So after a REBOOT, the script should be configured such that it only starts to monitor the WAN state AFTER the first successful WAN connection.

i.e. it isn't wise to blindly schedule the script from say init-start (either by using the delay parameter or either a static/dynamic cron schedule) but instead schedule the script from the WAN 'connected' event to prevent the possibly inconvenient REBOOT loop cycle if the WAN never ever recovers after a REBOOT."

For reference: https://github.com/RMerl/asuswrt-merlin.ng/wiki/User-scripts#wan-event
Yea I second your statements. Definitely not prudent to create a reboot boot loop. A more effective script would not be concerned with rebooting the router himself, but maybe just the critical network interfaces in question, and possibly some critical deem necessary services.
 
Similar threads

Similar threads

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