router: init proejct
This commit is contained in:
parent
bb49652985
commit
ce1c49dd6e
319
router/restart-wan-guide.html
Normal file
319
router/restart-wan-guide.html
Normal file
@ -0,0 +1,319 @@
|
||||
<html><head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<title> Restart WAN interface when internet is down - RMerl/asuswrt-merlin.ng GitHub Wiki </title>
|
||||
<style>
|
||||
#main {
|
||||
max-width: 38rem;
|
||||
margin: auto;
|
||||
overflow-wrap: break-word;
|
||||
min-width: 0;
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
body {
|
||||
background-image: url('/callToAction.svg');
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
#header_button {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
padding: 10px;
|
||||
border-style: ridge;
|
||||
border-color: lightgrey;
|
||||
border-width: thin;
|
||||
color: red;
|
||||
font-weight: bold;
|
||||
background-color: honeydew;
|
||||
font-size: large;
|
||||
}
|
||||
|
||||
#header_button p {
|
||||
margin-bottom: 0;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
#header_info {
|
||||
padding: 10px;
|
||||
border-style: ridge;
|
||||
border-color: lightgrey;
|
||||
border-width: thin;
|
||||
color: red;
|
||||
font-weight: bold;
|
||||
background-color: honeydew;
|
||||
font-size: large;
|
||||
}
|
||||
|
||||
#content,
|
||||
#index {
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
}
|
||||
|
||||
#footer_info {
|
||||
position: sticky;
|
||||
bottom: 0;
|
||||
padding: 10px;
|
||||
border-style: ridge;
|
||||
border-color: lightgrey;
|
||||
border-width: thin;
|
||||
color: red;
|
||||
font-weight: bold;
|
||||
background-color: honeydew;
|
||||
}
|
||||
|
||||
#footer_info .blocks {
|
||||
background: black;
|
||||
color: white;
|
||||
/* outline: 1px solid blue; */
|
||||
padding: .1em .2em;
|
||||
}
|
||||
|
||||
/* Hide useless-parts of transcluded HTML */
|
||||
.width-full.input-group {
|
||||
display: none;
|
||||
}
|
||||
|
||||
h5:nth-last-child(2) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.Box-row.wiki-more-pages-link {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.filter-bar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.Box-title>.octicon {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.anchor {
|
||||
display: none;
|
||||
}
|
||||
|
||||
pre {
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
#main {
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
.Counter {
|
||||
background-color: lightgray;
|
||||
border-radius: 20px;
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
table {
|
||||
max-width: 100%;
|
||||
overflow: auto;
|
||||
width: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.js-wiki-sidebar-toc-toggle-chevron-button {
|
||||
display: none;
|
||||
}
|
||||
|
||||
a.visit_url_original {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
line-height: 1.2em; /* adjust as needed */
|
||||
max-height: 1.2em; /* should match line-height */
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* White background for span */
|
||||
/* Rounded corners */
|
||||
/* Black border */
|
||||
.visit_url_pillbar {
|
||||
background-color: white;
|
||||
border-radius: 10px;
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
display: block;
|
||||
border: 1px solid black;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/* Broken Images */
|
||||
img:before {
|
||||
content: "⚠️ MISSING OR BROKEN IMAGE RENDERING ERROR: PLEASE VIEW ORIGINAL PAGE ON GITHUB.COM ⚠️";
|
||||
display: block;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "color-emoji";
|
||||
src: local("Apple Color Emoji"),
|
||||
local("Segoe UI Emoji"),
|
||||
local("Segoe UI Symbol"),
|
||||
local("Noto Color Emoji");
|
||||
}
|
||||
|
||||
.emoji {
|
||||
font-family: "color-emoji";
|
||||
}
|
||||
|
||||
table,
|
||||
th,
|
||||
td {
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
.visit_url_link {
|
||||
font-size: xx-large;
|
||||
}
|
||||
|
||||
.why_exist {
|
||||
position: relative;
|
||||
text-align: center;
|
||||
/* italics */
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
</style>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<!-- Not used, did not want to risk non-indexing. -->
|
||||
<!-- <meta property="og:url" content="https://github.com/RMerl/asuswrt-merlin.ng/wiki/Restart-WAN-interface-when-internet-is-down"> -->
|
||||
<!-- Did not want to risk contaminating content to be indexed. -->
|
||||
<!-- <meta property="og:description" content="not used"> -->
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:title" content="Restart WAN interface when internet is down - RMerl/asuswrt-merlin.ng GitHub Wiki">
|
||||
<script defer="defer" referrerpolicy="origin" src="Restart%20WAN%20interface%20when%20internet%20is%20down%20-%20RMerl_asuswrt-merlin.ng%20GitHub%20Wiki_files/s.js"></script><script data-cfasync="false" nonce="9aabea3a-9798-4f22-8774-260c71f290dc">try{(function(w,d){!function(fv,fw,fx,fy){if(fv.zaraz)console.error("zaraz is loaded twice");else{fv[fx]=fv[fx]||{};fv[fx].executed=[];fv.zaraz={deferred:[],listeners:[]};fv.zaraz._v="5858";fv.zaraz._n="9aabea3a-9798-4f22-8774-260c71f290dc";fv.zaraz.q=[];fv.zaraz._f=function(fz){return async function(){var fA=Array.prototype.slice.call(arguments);fv.zaraz.q.push({m:fz,a:fA})}};for(const fB of["track","set","debug"])fv.zaraz[fB]=fv.zaraz._f(fB);fv.zaraz.init=()=>{var fC=fw.getElementsByTagName(fy)[0],fD=fw.createElement(fy),fE=fw.getElementsByTagName("title")[0];fE&&(fv[fx].t=fw.getElementsByTagName("title")[0].text);fv[fx].x=Math.random();fv[fx].w=fv.screen.width;fv[fx].h=fv.screen.height;fv[fx].j=fv.innerHeight;fv[fx].e=fv.innerWidth;fv[fx].l=fv.location.href;fv[fx].r=fw.referrer;fv[fx].k=fv.screen.colorDepth;fv[fx].n=fw.characterSet;fv[fx].o=(new Date).getTimezoneOffset();if(fv.dataLayer)for(const fF of Object.entries(Object.entries(dataLayer).reduce(((fG,fH)=>({...fG[1],...fH[1]})),{})))zaraz.set(fF[0],fF[1],{scope:"page"});fv[fx].q=[];for(;fv.zaraz.q.length;){const fI=fv.zaraz.q.shift();fv[fx].q.push(fI)}fD.defer=!0;for(const fJ of[localStorage,sessionStorage])Object.keys(fJ||{}).filter((fL=>fL.startsWith("_zaraz_"))).forEach((fK=>{try{fv[fx]["z_"+fK.slice(7)]=JSON.parse(fJ.getItem(fK))}catch{fv[fx]["z_"+fK.slice(7)]=fJ.getItem(fK)}}));fD.referrerPolicy="origin";fD.src="/cdn-cgi/zaraz/s.js?z="+btoa(encodeURIComponent(JSON.stringify(fv[fx])));fC.parentNode.insertBefore(fD,fC)};["complete","interactive"].includes(fw.readyState)?zaraz.init():fv.addEventListener("DOMContentLoaded",zaraz.init)}}(w,d,"zarazData","script");window.zaraz._p=async eC=>new Promise((eD=>{if(eC){eC.e&&eC.e.forEach((eE=>{try{const eF=d.querySelector("script[nonce]"),eG=eF?.nonce||eF?.getAttribute("nonce"),eH=d.createElement("script");eG&&(eH.nonce=eG);eH.innerHTML=eE;eH.onload=()=>{d.head.removeChild(eH)};d.head.appendChild(eH)}catch(eI){console.error(`Error executing script: ${eE}\n`,eI)}}));Promise.allSettled((eC.f||[]).map((eJ=>fetch(eJ[0],eJ[1]))))}eD()}));zaraz._p({"e":["(function(w,d){})(window,document)"]});})(window,document)}catch(e){throw fetch("/cdn-cgi/zaraz/t"),e;};</script><script>(function(w,d){})(window,document)</script><script>(function(w,d){})(window,document)</script><style>:is([id*='google_ads_iframe'],[id*='taboola-'],.taboolaHeight,.taboola-placeholder,#top-ad,#credential_picker_container,#credentials-picker-container,#credential_picker_iframe,[id*='google-one-tap-iframe'],#google-one-tap-popup-container,.google-one-tap__module,.google-one-tap-modal-div,#amp_floatingAdDiv,#ez-content-blocker-container) {display:none!important;min-height:0!important;height:0!important;}</style></head>
|
||||
|
||||
<body>
|
||||
<div id="main">
|
||||
<nav id="header_button">
|
||||
<p>Content mirrored for search engine indexing from:</p>
|
||||
<div>
|
||||
<span class="visit_url_pillbar">
|
||||
<a href="https://github.com/RMerl/asuswrt-merlin.ng/wiki/Restart-WAN-interface-when-internet-is-down" class="visit_url_original">https://github.com/RMerl/asuswrt-merlin.ng/wiki/Restart-WAN-interface-when-internet-is-down</a>
|
||||
</span>
|
||||
|
||||
</div>
|
||||
<div class="why_exist">
|
||||
<a href="https://github-wiki-see.page/">Why does this service exist?</a>
|
||||
</div>
|
||||
</nav>
|
||||
<aside id="header_info">
|
||||
<!-- Last Modified Date added around here from redirect checker-->
|
||||
<p>📅 Last Modified: Fri, 25 Dec 2020 12:44:07 GMT</p></aside>
|
||||
<article id="content">
|
||||
<h1>Restart WAN interface when internet is down - RMerl/asuswrt-merlin.ng GitHub Wiki</h1>
|
||||
<div id="mirrored"> <script data-cfasync="false" nonce="9aabea3a-9798-4f22-8774-260c71f290dc">try{(function(w,d){!function(fv,fw,fx,fy){if(fv.zaraz)console.error("zaraz is loaded twice");else{fv[fx]=fv[fx]||{};fv[fx].executed=[];fv.zaraz={deferred:[],listeners:[]};fv.zaraz._v="5858";fv.zaraz._n="9aabea3a-9798-4f22-8774-260c71f290dc";fv.zaraz.q=[];fv.zaraz._f=function(fz){return async function(){var fA=Array.prototype.slice.call(arguments);fv.zaraz.q.push({m:fz,a:fA})}};for(const fB of["track","set","debug"])fv.zaraz[fB]=fv.zaraz._f(fB);fv.zaraz.init=()=>{var fC=fw.getElementsByTagName(fy)[0],fD=fw.createElement(fy),fE=fw.getElementsByTagName("title")[0];fE&&(fv[fx].t=fw.getElementsByTagName("title")[0].text);fv[fx].x=Math.random();fv[fx].w=fv.screen.width;fv[fx].h=fv.screen.height;fv[fx].j=fv.innerHeight;fv[fx].e=fv.innerWidth;fv[fx].l=fv.location.href;fv[fx].r=fw.referrer;fv[fx].k=fv.screen.colorDepth;fv[fx].n=fw.characterSet;fv[fx].o=(new Date).getTimezoneOffset();if(fv.dataLayer)for(const fF of Object.entries(Object.entries(dataLayer).reduce(((fG,fH)=>({...fG[1],...fH[1]})),{})))zaraz.set(fF[0],fF[1],{scope:"page"});fv[fx].q=[];for(;fv.zaraz.q.length;){const fI=fv.zaraz.q.shift();fv[fx].q.push(fI)}fD.defer=!0;for(const fJ of[localStorage,sessionStorage])Object.keys(fJ||{}).filter((fL=>fL.startsWith("_zaraz_"))).forEach((fK=>{try{fv[fx]["z_"+fK.slice(7)]=JSON.parse(fJ.getItem(fK))}catch{fv[fx]["z_"+fK.slice(7)]=fJ.getItem(fK)}}));fD.referrerPolicy="origin";fD.src="/cdn-cgi/zaraz/s.js?z="+btoa(encodeURIComponent(JSON.stringify(fv[fx])));fC.parentNode.insertBefore(fD,fC)};["complete","interactive"].includes(fw.readyState)?zaraz.init():fv.addEventListener("DOMContentLoaded",zaraz.init)}}(w,d,"zarazData","script");window.zaraz._p=async eC=>new Promise((eD=>{if(eC){eC.e&&eC.e.forEach((eE=>{try{const eF=d.querySelector("script[nonce]"),eG=eF?.nonce||eF?.getAttribute("nonce"),eH=d.createElement("script");eG&&(eH.nonce=eG);eH.innerHTML=eE;eH.onload=()=>{d.head.removeChild(eH)};d.head.appendChild(eH)}catch(eI){console.error(`Error executing script: ${eE}\n`,eI)}}));Promise.allSettled((eC.f||[]).map((eJ=>fetch(eJ[0],eJ[1]))))}eD()}));zaraz._p({"e":["(function(w,d){})(window,document)"]});})(window,document)}catch(e){throw fetch("/cdn-cgi/zaraz/t"),e;};</script><p>If
|
||||
you frequently lose internet connectivity with error like "Your ISP
|
||||
DHCP does not function correctly" then you might want these script. It
|
||||
is most useful for people with some router model like AC86U.</p>
|
||||
<h1><a href="#advanced-script" aria-hidden="true" class="anchor" id="advanced-script"></a>Advanced script</h1>
|
||||
<p>Fantastic scripts have been written by community users. It is better to use them. See these links.</p>
|
||||
<p><a href="https://www.snbforums.com/threads/need-a-script-that-auto-reboot-if-internet-is-down.43819/post-371791" rel="nofollow ugc">https://www.snbforums.com/threads/need-a-script-that-auto-reboot-if-internet-is-down.43819/post-371791</a></p>
|
||||
<p><a href="https://github.com/MartineauUK/Chk-WAN" rel="nofollow ugc">https://github.com/MartineauUK/Chk-WAN</a></p>
|
||||
<h1><a href="#simple-script" aria-hidden="true" class="anchor" id="simple-script"></a>Simple script</h1>
|
||||
<p>Here below is a very basic script to run every 3 minutes and restart
|
||||
WAN interface if 10 pings fail. Adjust as desired. Please see above for
|
||||
more comprehensive scripts that do a better job.</p>
|
||||
<ol>
|
||||
<li>Create and edit a new script file:</li>
|
||||
</ol>
|
||||
<pre><code>nano /jffs/scripts/custom_wan_monitor
|
||||
</code></pre>
|
||||
<ol start="2">
|
||||
<li>Write in this script:</li>
|
||||
</ol>
|
||||
<pre><code>#!/bin/sh
|
||||
|
||||
PING_HOST=1.1.1.1
|
||||
PING_WAIT=2
|
||||
MAX_TRIES=10
|
||||
|
||||
wan_monitor(){
|
||||
echo "WAN Monitor: $@"|/usr/bin/logger -s
|
||||
}
|
||||
restart_wan_interface(){
|
||||
wan_monitor "Force restarting WAN interface now..."
|
||||
service "restart_wan_if 0"
|
||||
sleep 10
|
||||
service "restart_wan_if 1"
|
||||
wan_monitor "WAN interface is restarted."
|
||||
}
|
||||
ping_test(){
|
||||
count_tries=0
|
||||
ping_test_passed=0
|
||||
wan_monitor "Running ping test..."
|
||||
while [ $count_tries -lt $MAX_TRIES ]; do
|
||||
if /bin/ping -c 1 -W $PING_WAIT $@ >/tmp/wan_check.log; then
|
||||
ping_test_passed=1
|
||||
wan_monitor "Ping test succeeded within $PING_WAIT secs."
|
||||
break
|
||||
else
|
||||
sleep 1
|
||||
let count_tries=count_tries+1
|
||||
wan_monitor "Ping failed [$count_tries]"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
ping_test $PING_HOST
|
||||
|
||||
if [ $ping_test_passed -gt 0 ]; then
|
||||
wan_monitor "Internet was reachable. No need to restart WAN."
|
||||
break
|
||||
else
|
||||
wan_monitor "Pings failed. Internet must be down."
|
||||
restart_wan_interface
|
||||
fi
|
||||
</code></pre>
|
||||
<ol start="3">
|
||||
<li>Run this full command:</li>
|
||||
</ol>
|
||||
<pre><code>touch /jffs/scripts/init-start ; echo 'cru a custom_wan_monitor "*/3 * * * * /jffs/scripts/custom_wan_monitor"' >> /jffs/scripts/init-start ; cat /jffs/scripts/init-start
|
||||
</code></pre>
|
||||
<p>See that it appended a new line to <code>init-start</code>.</p>
|
||||
<ol start="4">
|
||||
<li>Make both executable:</li>
|
||||
</ol>
|
||||
<pre><code>chmod 755 /jffs/scripts/init-start /jffs/scripts/custom_wan_monitor
|
||||
</code></pre>
|
||||
<p>Reboot router.</p>
|
||||
<p>See cron job is now listed:</p>
|
||||
<pre><code>cru l
|
||||
</code></pre>
|
||||
<p>Check syslog to see that script runs continuously.</p>
|
||||
<p>Read here for help customizing cron job timing.
|
||||
<a href="https://crontab.guru/" rel="nofollow ugc">https://crontab.guru/</a></p>
|
||||
<h1><a href="#references" aria-hidden="true" class="anchor" id="references"></a>References</h1>
|
||||
<p>Some relevant links for the ongoing issue:</p>
|
||||
<p><a href="https://www.snbforums.com/threads/your-isps-dhcp-does-not-function-correctly.43178/" rel="nofollow ugc">https://www.snbforums.com/threads/your-isps-dhcp-does-not-function-correctly.43178/</a></p>
|
||||
<p><a href="https://www.snbforums.com/threads/new-rt-ax88u-no-wan-4-days-later.57960/" rel="nofollow ugc">https://www.snbforums.com/threads/new-rt-ax88u-no-wan-4-days-later.57960/</a></p>
|
||||
<p><a href="https://www.snbforums.com/threads/ac3100-primary-wan-assigned-show-your-isps-dhcp-does-not-function-correctly.61902/" rel="nofollow ugc">https://www.snbforums.com/threads/ac3100-primary-wan-assigned-show-your-isps-dhcp-does-not-function-correctly.61902/</a></p>
|
||||
<p><a href="https://www.snbforums.com/threads/asus-firmware-dhcp-continuous-mode-potential-fix-for-isps-dhcp-did-not-function-properly.61907/" rel="nofollow ugc">https://
|
||||
www.snbforums.com/threads/asus-firmware-dhcp-continuous-mode-potential-
|
||||
fix-for-isps-dhcp-did-not-function-properly.61907/</a></p>
|
||||
<p><a href="https://www.snbforums.com/threads/your-isps-dhcp-does-not-function-correctly.67033/" rel="nofollow ugc">https://www.snbforums.com/threads/your-isps-dhcp-does-not-function-correctly.67033/</a></p>
|
||||
<p><a href="https://www.snbforums.com/threads/rt-ax88u-router-behind-modem-router-isp.67312/" rel="nofollow ugc">https://www.snbforums.com/threads/rt-ax88u-router-behind-modem-router-isp.67312/</a></p>
|
||||
<p><a href="https://www.snbforums.com/threads/rt-ax88u-internet-status-disconnected.67331/" rel="nofollow ugc">https://www.snbforums.com/threads/rt-ax88u-internet-status-disconnected.67331/</a></p>
|
||||
<p><a href="https://www.snbforums.com/threads/ac86u-random-disconnects-but-stay-on.67927/" rel="nofollow ugc">https://www.snbforums.com/threads/ac86u-random-disconnects-but-stay-on.67927/</a></p>
|
||||
<p><a href="https://www.snbforums.com/threads/ax88u-behind-isp-router-internet-drops-vpn-isp-dhcp-does-not-function.68438/" rel="nofollow ugc">https://www.snbforums.com/threads/ax88u-behind-isp-router-internet-drops-vpn-isp-dhcp-does-not-function.68438/</a></p>
|
||||
<p><a href="https://www.snbforums.com/threads/wan_connection-isps-dhcp-did-not-function-properly.56226/" rel="nofollow ugc">https://www.snbforums.com/threads/wan_connection-isps-dhcp-did-not-function-properly.56226/</a></p>
|
||||
<script defer="defer" src="Restart%20WAN%20interface%20when%20internet%20is%20down%20-%20RMerl_asuswrt-merlin.ng%20GitHub%20Wiki_files/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon="{"rayId":"95c1d5aab9d3b5b5","version":"2025.6.2","r":1,"serverTiming":{"name":{"cfExtPri":true,"cfEdge":true,"cfOrigin":true,"cfL4":true,"cfSpeedBrain":true,"cfCacheStatus":true}},"token":"4645764ca8384bfc86034b71f1dafd76","b":1}" crossorigin="anonymous"></script>
|
||||
</div>
|
||||
</article>
|
||||
<nav id="index">
|
||||
<a href="https://github-wiki-see.page/m/RMerl/asuswrt-merlin.ng/wiki_index">🗂️ Page Index for this GitHub Wiki</a>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
|
||||
</body></html>
|
||||
26
router/run.sh
Executable file
26
router/run.sh
Executable file
@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Variables
|
||||
REMOTE_HOST="router"
|
||||
REMOTE_DIR="/jffs/scripts/" # Replace with the destination directory on the remote server
|
||||
RESTART_SCRIPT="$(git rev-parse --show-toplevel)/router/scripts/restart-wan" # Replace with the path to the first local file
|
||||
INIT_SCRIPT="$(git rev-parse --show-toplevel)/router/scripts/init" # Replace with the path to the second local file
|
||||
|
||||
# Prompt for the password
|
||||
read -sp "Enter SSH password: " SSH_PASSWORD
|
||||
echo
|
||||
|
||||
# Init dir
|
||||
sshpass -p "$SSH_PASSWORD" ssh "$REMOTE_HOST" "mkdir -p $REMOTE_DIR"
|
||||
|
||||
# Copy files to the remote directory
|
||||
sshpass -p "$SSH_PASSWORD" scp "$RESTART_SCRIPT" "$REMOTE_HOST:$REMOTE_DIR"
|
||||
sshpass -p "$SSH_PASSWORD" scp "$INIT_SCRIPT" "$REMOTE_HOST:$REMOTE_DIR"
|
||||
|
||||
# Change permissions to 775
|
||||
sshpass -p "$SSH_PASSWORD" ssh "$REMOTE_HOST" "chmod 775 $REMOTE_DIR/*"
|
||||
|
||||
# Execute the init
|
||||
sshpass -p "$SSH_PASSWORD" ssh "$REMOTE_HOST" "$REMOTE_DIR/$(basename $INIT_SCRIPT) &"
|
||||
|
||||
echo "Files copied, permissions changed, and executed."
|
||||
3
router/scripts/init
Normal file
3
router/scripts/init
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
cru a restart-wan "* * * * * /jffs/scripts/restart-wan"
|
||||
52
router/scripts/restart-wan
Normal file
52
router/scripts/restart-wan
Normal file
@ -0,0 +1,52 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Configuration
|
||||
PING_HOST="1.1.1.1"
|
||||
PING_WAIT=2
|
||||
MAX_TRIES=4
|
||||
|
||||
# Function to log messages
|
||||
wan_monitor() {
|
||||
echo "WAN Monitor: $@" | /usr/bin/logger -s
|
||||
}
|
||||
|
||||
# Function to restart the WAN interface
|
||||
restart_wan_interface() {
|
||||
wan_monitor "Force restarting WAN interface now..."
|
||||
service "restart_wan_if 0" # Bring down the interface
|
||||
sleep 10 # Wait for 10 seconds
|
||||
service "restart_wan_if 1" # Bring up the interface
|
||||
wan_monitor "WAN interface is restarted."
|
||||
}
|
||||
|
||||
# Function to perform a ping test
|
||||
ping_test() {
|
||||
local count_tries=0
|
||||
local ping_test_passed=0
|
||||
wan_monitor "Running ping test..."
|
||||
|
||||
while [ $count_tries -lt $MAX_TRIES ]; do
|
||||
if /bin/ping -c 1 -W $PING_WAIT $@ >/tmp/wan_check.log; then
|
||||
ping_test_passed=1
|
||||
wan_monitor "Ping test succeeded within $PING_WAIT secs."
|
||||
exit 0
|
||||
else
|
||||
sleep 1
|
||||
count_tries=$((count_tries + 1))
|
||||
wan_monitor "Ping failed [$count_tries]"
|
||||
fi
|
||||
done
|
||||
|
||||
return $ping_test_passed
|
||||
}
|
||||
|
||||
|
||||
|
||||
if [ $(ping_test $PING_HOST) -gt 0 ]; then
|
||||
wan_monitor "Internet was reachable. No need to restart WAN."
|
||||
else
|
||||
wan_monitor "Pings failed. Internet must be down."
|
||||
restart_wan_interface
|
||||
fi
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user