Page 1 of 1

I need a script to determine if the pppoe-out1 state is connected

Posted: Wed Apr 07, 2021 5:53 pm
by cillininfo
I need a script to determine if the pppoe-out1 state is connected

If not, retest every three seconds

Run if connected

Time delay: 3S

/Int PPPoE client set pppoe-out2 disabled = no

Re: I need a script to determine if the pppoe-out1 state is connected  [SOLVED]

Posted: Thu Apr 08, 2021 7:52 am
by ajdmh
:if ([/interface get [/interface  find name=pppoe-out1] running]=yes) do={ 
delay 3000
/interface pppoe-client set pppoe-out2 disabled=no}
The script is written according to your ideas,
However, there is a big problem with your logic:
If pppoe-out1 is in the connected state, then pppoe-out2 will keep repeating the connection and disconnection actions.

Maybe the following is right for you:
:if ([/interface get [/interface  find name=pppoe-out2] disabled]=yes) do={
:if ([/interface get [/interface  find name=pppoe-out1] running]=yes) do={ 
delay 3000
/interface pppoe-client set pppoe-out2 disabled=no}}

Re: I need a script to determine if the pppoe-out1 state is connected

Posted: Thu Apr 08, 2021 3:27 pm
by msatter
Tested and working to determine if the connection is active:
:if (([/interface pppoe-client monitor pppoe-out1 as-value once]->"status") = "connected") do={:put "connected"}


{ 
:local limiter
while (([/interface pppoe-client monitor pppoe-out1 as-value once]->"status") != "connected") do={
/interface set pppout-out1 disable=yes
:set $limiter ($limiter + 1)
:if (($limiter % 5) = 0) do={delay 5m} else={delay 3s}
/interface set pppout-out1 disable=no
}
}
After 5 retries it waits 5 minutes before enabling an try again 5 times. This because ISP do tend to block new connects if you tried a few times and give you a 5 minute cool-down period. After that you can try again a few times.

Explanation of the % :
modulo operation :put (5 % 3);