Community discussions

MikroTik App
 
dima1002
Member Candidate
Member Candidate
Topic Author
Posts: 160
Joined: Fri Jan 26, 2018 8:40 pm

Script - do not remove

Sun Mar 06, 2022 12:19 pm

Hello,

how can I NOT remove the default route here if WAN1 is found?
if ([/interface get WAN1]) do={/ip route remove [/ip route find dst-address=0.0.0.0/0]}
 
msatter
Forum Guru
Forum Guru
Posts: 2897
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Script - do not remove

Sun Mar 06, 2022 2:04 pm

if (![/interface get WAN1]) do={/ip route remove [/ip route find dst-address=0.0.0.0/0]}
It is the "!"

Or
if ([/interface get WAN1]) do={} else={/ip route remove [/ip route find dst-address=0.0.0.0/0]}
 
dima1002
Member Candidate
Member Candidate
Topic Author
Posts: 160
Joined: Fri Jan 26, 2018 8:40 pm

Re: Script - do not remove

Mon Mar 07, 2022 9:24 am

thank you very much, it works perfectly
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script - do not remove

Mon Mar 07, 2022 1:19 pm

this:
[/interface get WAN1]
causes an error if WAN1 is NOT found and the script is aborted
and from that we can't get the true or false value, but all the properties of the interface
For example try
:put [/interface get WAN1]

How do correctly do that (ignoring why you delete the route):
# if 0 interface named WAN1 is found, delete (all) routes that have 0.0.0.0/0 as destination address
:if ([:len [/interface find where name="WAN1"]] = 0) do={ /ip route remove [find where dst-address=0.0.0.0/0] }

# if (exactly) 1 interface named WAN1 is found, delete (all) routes that have 0.0.0.0/0 as destination address
:if ([:len [/interface find where name="WAN1"]] = 1) do={ /ip route remove [find where dst-address=0.0.0.0/0] }

Who is online

Users browsing this forum: stefanau and 24 guests