What's new

Need a script that auto reboot if internet is down

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

Sorry, I must be more than a dummy, because I'm still not 100% sure what I need to do! I realise I have to create some files, but 1) What do I call them? 2) What needs to go inside them exactly? 3) Do I need to change any user-defined parameters and if so, which ones and where are they? and 4) Where do the files need to be saved? Also, am I right in thinking that I need to change some of the read/write attributes for the file(s)?
 
Sorry, I must be more than a dummy, because I'm still not 100% sure what I need to do! I realise I have to create some files, but 1) What do I call them? 2) What needs to go inside them exactly? 3) Do I need to change any user-defined parameters and if so, which ones and where are they? and 4) Where do the files need to be saved? Also, am I right in thinking that I need to change some of the read/write attributes for the file(s)?

As per the 'ChkWAN.sh' installation instructions here, you copy'n'paste the one-line and press ENTER.

The script is now installed, but needs to be tested.

If the script's defaults meet your requirements, you simply need to inform the router to auto-execute the monitoring in the background.

Your post shows that you refer to WinSCP, so I provided a link should you wish to modify/create your own scripts or were unsure how to create script wan-start.

Not sure how I can improve instructions...READ THIS in particular the link to the Wiki which describes which script names are recognised/reserved for customising the router's feature set.
 
As per the 'ChkWAN.sh' installation instructions here, you copy'n'paste the one-line and press ENTER.
So where do I "copy'n'paste" the line into? And do I need to create files in both /jffs/configs and jffs/scripts as per the mini guide?
 
Well, after much effort, flitting between different web pages, I finally realised that I needed to use xShell to install the script, which it seems to have done. No idea what to do next though, so could I have some simple instructions how best to set up the WAN checker. For instance, would this be a good option to use, "You could configure the cron schedule such that the scipt[sic] will restart the WAN say 3 times, but every fourth attempt will action the REBOOT." and if so, how would I set it up? Or alternatively, would there be a better way to configure it and if so, may I have instructions for that as well? Also, how exactly do I test that it's working correctly?
Screenshot - 11_12_2019 , 20_51_53.png
 
Abusive posts removed. Please keep it civilized folks.
 
I'm also confused by this script. I did the one liner and now have ChkWan.sh in /jffs/scripts. I tested it and the results were fine. Now here is where the confusion comes in. It sounds like you want the user to create a file called 'wan-start' in /jffs/scripts and copy this line into it:

sh /jffs/scripts/wan-check.sh &

Is 'wan-start' some secret sauce that the OS runs periodically? If so, I'm a bit amazed. But, the every 30 seconds thing is a bit of overkill, so how about providing a cron job request for one hour. I can't quite understand the 3 times and 1 for reboot. Would like to see a proper example.

Thanks
 
I'm also confused by this script. I did the one liner and now have ChkWan.sh in /jffs/scripts. I tested it and the results were fine. Now here is where the confusion comes in. It sounds like you want the user to create a file called 'wan-start' in /jffs/scripts and copy this line into it:
Code:
sh /jffs/scripts/wan-check.sh &
Is 'wan-start' some secret sauce that the OS runs periodically? If so, I'm a bit amazed.
No secret...There is a wealth of information in the RMerlin Wiki .....specifically User scripts should quell your amazement.
I can't quite understand the 3 times and 1 for reboot. Would like to see a proper example.
I posted a static example of 4 times restart WAN, and the 5th Reboot in post #24

NOTE: Ideally you would reset the cru (cron) sequence each time there is a successful WAN restart.
 
Okay, I understand that wan-start is an OS secret sauce file, and for the benefit of others that have not had the light of bash all upon them, you would:

cd /jffs/scripts
nano wan-start
then copy into this file:
#!/bin/sh
sh /jffs/scripts/wan-check.sh &

Now, as for post 24 it appears their is considerable controversy over syntax and just where the lines should be loaded. But, no need for a condescending reply. I'll soldier on.
 
Last edited:
Now, as for post 24 it appears their is considerable controversy over syntax and just where the lines should be loaded. But, no need for a condescending reply. I'll soldier on.
Not sure what you mean.:confused:
 
Last edited:
  • Like
Reactions: Cam
Thanks for this script Martineau.
Please could you help me.
I created a file ChkWAN.sh with the content at /jffs/scripts
Create another file wan-start.sh with this content

#!/bin/sh
cru a test "0 * * * * /jffs/scripts/ChkWAN.sh wan &"

both scripts are executable.

But when I restart the router there are no cru tasks.
Please what's wrong?

Thanks
 
Use wan-start without -.sh and chmod 0755 and shebang on top of it.
 
Last edited:
@Martineau many thanks for this! Will surely help my parents' router.

Installation instructions for anyone who's interested (ChkWAN configured with: wan (for restarting WAN without rebooting the router), quiet (quieter log, feel free to remove this to make sure it's working properly in the beginning), and nowait (no 10 second delay as it's a cronjob):

Download the latest ChkWAN script into /jffs/scripts/ (note: custom scripts must be enabled)
Code:
curl --retry 3 "https://raw.githubusercontent.com/MartineauUK/Chk-WAN/master/ChkWAN.sh" -o "/jffs/scripts/ChkWAN.sh" && chmod 755 "/jffs/scripts/ChkWAN.sh"

Run the script once to test it out, no action taken (no reboot or wan reset):
Code:
/jffs/scripts/ChkWAN.sh noaction once nowait

Going with the cronjob method and assuming that there is no "/jffs/scripts/services-start" file created yet, create the services-start file and make it executable:
Code:
echo "#!/bin/sh" > /jffs/scripts/services-start
echo 'cru a ChkWAN "*/5 * * * * /jffs/scripts/ChkWAN.sh wan quiet nowait"' >> /jffs/scripts/services-start
chmod 0755 /jffs/scripts/services-start

If /jffs/scripts/services-start already exists and has content, simply append the following to it:
Code:
cru a ChkWAN "*/5 * * * * /jffs/scripts/ChkWAN.sh wan quiet nowait"

You can either reboot your router or manually run the same command to start running the script every 5 minutes:
Code:
cru a ChkWAN "*/5 * * * * /jffs/scripts/ChkWAN.sh wan quiet nowait"
 
@Martineau many thanks for this! Will surely help my parents' router.

Installation instructions for anyone who's interested (ChkWAN configured with: wan (for restarting WAN without rebooting the router), quiet (quieter log, feel free to remove this to make sure it's working properly in the beginning), and nowait (no 10 second delay as it's a cronjob):

Download the latest ChkWAN script into /jffs/scripts/ (note: custom scripts must be enabled)
Code:
curl --retry 3 "https://raw.githubusercontent.com/MartineauUK/Chk-WAN/master/ChkWAN.sh" -o "/jffs/scripts/ChkWAN.sh" && chmod 755 "/jffs/scripts/ChkWAN.sh"

Run the script once to test it out, no action taken (no reboot or wan reset):
Code:
/jffs/scripts/ChkWAN.sh noaction once nowait

Going with the cronjob method and assuming that there is no "/jffs/scripts/services-start" file created yet, create the services-start file and make it executable:
Code:
echo "#!/bin/sh" > /jffs/scripts/services-start
echo 'cru a ChkWAN "*/5 * * * * /jffs/scripts/ChkWAN.sh wan quiet nowait"' >> /jffs/scripts/services-start
chmod 0755 /jffs/scripts/services-start

If /jffs/scripts/services-start already exists and has content, simply append the following to it:
Code:
cru a ChkWAN "*/5 * * * * /jffs/scripts/ChkWAN.sh wan quiet nowait"

You can either reboot your router or manually run the same command to start running the script every 5 minutes:
Code:
cru a ChkWAN "*/5 * * * * /jffs/scripts/ChkWAN.sh wan quiet nowait"


I just have a two line entry in nat-start which works just as well
Code:
#!/bin/sh
cru a CheckWAN "30 */1 * * * sh /jffs/scripts/ChkWAN.sh nowait reboot forcesmall curlrate=100 verbose ping=1.1.1.1,9.9.9.9 tries=4 fails=4"

( This runs every hour at 30 past the hour and downloads small file- the download speed must exceed 100Byte/sec otherwise a fail condition exists. It tries 4 times - then reboots router if 4 successive fail conditions occur ( either failed ping or failed download or both). Example syslog on the half hour follows:-
Code:
Feb 18 22:30:01 RT-AC5300-0680 (ChkWAN.sh): 24425 v1.13 Monitoring WAN connection using 2 target PING hosts (1.1.1.1 9.9.9.9) (Tries=4)
Feb 18 22:30:01 RT-AC5300-0680 (ChkWAN.sh): 24425 Monitoring pass 1 out of 4
Feb 18 22:30:01 RT-AC5300-0680 (ChkWAN.sh): 24425 Starting cURL 'small' data transfer.....(Expect 500Byte download = <1 second)
Feb 18 22:30:01 RT-AC5300-0680 (ChkWAN.sh): 24425 NOTE: Transfer rate must be faster than 100 Bytes/sec
Feb 18 22:30:04 RT-AC5300-0680 (ChkWAN.sh): 24425 cURL 433Byte transfer took: 00:02.64 secs @ 163 B/sec
eb 18 22:30:04 RT-AC5300-0680 (ChkWAN.sh): 24425 Monitoring WAN connection OK.....(using 'small' ~500Byte cURL data transfer OK); Terminating due to ACTIVE cron schedule
 
Last edited:
@Martineau , thanks for this useful scripts!
Is there a way to log it in its own log file instead of the syslog? After awhile, the syslog is flooded with ChkWAN and other logs are wiped due to the limited syslog size.
Thanks!
 
@Martineau , thanks for this useful scripts!
Is there a way to log it in its own log file instead of the syslog? After awhile, the syslog is flooded with ChkWAN and other logs are wiped due to the limited syslog size.
Thanks!

You can try adding the "quiet" parameter which will lead to the only output being if/when ChkWAN is renewing DHCP/restarting WAN and/or rebooting the router as per https://github.com/MartineauUK/Chk-WAN/blob/master/ChkWAN.sh:

Code:
"Renewing DHCP and restarting" $WAN_NAME "(Action="$ACTION")"

Or:

Code:
"Rebooting..... (Action="$ACTION")"
 
jackiechun,
I did everything according to your instructions from the post 73. Thank you.
How to determine at the moment that the script ChkWAN.sh is successfully launched and running?
Is it possible to see the running script ChkWAN.sh process in the PuTTY?
 
Last edited:
jackiechun,
I did everything according to your instructions from the post 73. Thank you.
How to determine at the moment that the script ChkWAN.sh is successfully launched and running?
Is it possible to see the running script ChkWAN.sh process in the PuTTY?
Yes.

You can manually test the script with the default PING method, and the script will simply passively report the status, rather proactively restart the WAN or REBOOT
Code:
./ChkWAN.sh noaction once nowait


Near the bottom of the README.md
 

Butterfly Bones,​

Thanks for the hint. Inattentively read the README.md

I launched the downloaded script and did not make any changes. If I understood correctly, the script after four attempts reboots the router.

I run the downloaded script and did not make any changes. If I understood correctly, the script after four checks REBOOT the ROUTER?

What line should be added or changed in the script so that when the connection is disappeared the first four times RESTART the WAN, and for the fifth time REBOOT the ROUTER?

On this topic there was an explanation from @Martineau, quoting:
e.g. Every 3mins check and restart the WAN if it is DOWN, but make every 5th check a call to REBOOT if WAN is DOWN
cru a Restart_WAN "0,3,6,9, 15,18,21,24, 30,33,36,39, 45,48,51,54, * * * *" /jffs/scripts/ChkWAN.sh wan force nowait
cru a Reboot_WAN " 12, 27, 42, 57 * * * *" /jffs/scripts/ChkWAN.sh reboot force nowait

In my script ChkWAN.sh there are such commented lines:
# Cron schedule may be reset /jffs/scripts/ChkWAN_Reset_CRON.sh if you have:
#
# Set up a static cron schedule every 10 minutes 2 times WAN Restart 3rd REBOOT
# cru a Restart_WAN 00,10,30,40 * * * * /jffs/scripts/ChkWAN.sh wan force nowait
# cru a Reboot_WAN 20,50 * * * * /jffs/scripts/ChkWAN.sh reboot force nowait
# but /jffs/scripts/ChkWAN_Reset_CRON.sh can change after very successful WAN UP check (Syslog monitor is better!!!?)
# cru a Restart_WAN 28,38,58,8 * * * * /jffs/scripts/ChkWAN.sh wan force nowait
# cru a Reboot_WAN 48,18 * * * * /jffs/scripts/ChkWAN.sh reboot force nowait

But I did not understand which in order the line needs to be changed into the script

Please help. Thanks.
 
Last edited:

Similar threads

Sign Up For SNBForums Daily Digest

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