What's new

[solved] Script check connetion - restart wan RT-AC68

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

Alkuimista

Occasional Visitor
I put this script in the jffs/scripts folder, in order to restart wan whenever the router is not connected to the internet.

Code:
#!/bin/bash
x=`ping -c1 google.com 2>&1 | grep unknown`
if [ ! "$x" = "" ]; then
        echo "It's down!! Attempting to restart."
        service restart_wan

fi

After that I made a wan-start file and I call the scipt from there with :

Code:
#!/bin/sh
sleep 60
/jffs/scripts/connection_check.sh

I don't have physical access to the router, and I made the script through ssh over the internet, but I am seeing the router most of the time down.

Could someone give me some insight on why this script would not work?

Thanks in advanced

EDIT : Is there a simple way of adding the echo line to the log? Because I am accessing the router remotely if the connection drops obviously I can't see it, and only thought about that now! :)
 
Last edited:
For syslog:
logger "text to appear in log"

The wan-start file is run when the wan starts, say during boot.
Then it waits 60 seconds and runs your script once, then is dormant until the next wan start event happens.

You need to add a cron job to run your script periodically or run a loop in wan start.
 
For syslog:
logger "text to appear in log"

The wan-start file is run when the wan starts, say during boot.
Then it waits 60 seconds and runs your script once, then is dormant until the next wan start event happens.

You need to add a cron job to run your script periodically or run a loop in wan start.

Hmmm, many thanks for the info, never saw the problem with the loop till you brought it :)

Logger it's really a nice help

Is it better to do a loop in wan-start or use a cron job in your opinion? Also what's the best approach for that?
 
And unless you have bash installed, correct the shebang!
 
A loop constantly delays finishing the wan-start script. If you ever were to add more commands after the loop they perhaps never run.
You best remove the code in wan-start and add a cron job with:
Code:
#!/bin/sh
cru a CheckWAN "*/5 * * * * /jffs/scripts/connection_check.sh"
This adds the cron job to crontab at every boot and runs the script every 5 minutes.
Check if it is added with cru l (lower case L)

Make sure all scripts in jffs/scripts are executable:
Code:
chmod a+rx /jffs/scripts/*
And you should be good to go.
 
A loop constantly delays finishing the wan-start script. If you ever were to add more commands after the loop they perhaps never run.
You best remove the code in wan-start and add a cron job with:
Code:
#!/bin/sh
cru a CheckWAN "*/5 * * * * /jffs/scripts/connection_check.sh"
This adds the cron job to crontab at every boot and runs the script every 5 minutes.
Check if it is added with cru l (lower case L)

Make sure all scripts in jffs/scripts are executable:
Code:
chmod a+rx /jffs/scripts/*
And you should be good to go.


Nice catch the "bash", totally missed it
Many thank's for your answers, I will try that way
 
I'm not sure your code ever catches the WAN down.
Why not make it simpler:
Code:
#!/bin/sh

if ! ping -c 1 google.com >/dev/null;then
        echo "It's down!! Attempting to restart."
        logger "WAN is down!! Attempting to restart."
        service restart_wan
fi
 
Last edited:
I'm not sure your code ever catches the WAN down.
Why not make it simpler:
Code:
#!/bin/sh

if ! ping -c 1 google.com >/dev/null;then
        echo "It's down!! Attempting to restart."
        logger "WAN is down!! Attempting to restart."
        service restart_wan
fi

Everything is running smooth now :)
I had tried "ping -c 1 google.com >/dev/null" but for some reason, it was not working.
I can't thank you enough! You are the best! :)
 

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