Community discussions

MikroTik App
 
siu
just joined
Topic Author
Posts: 1
Joined: Tue May 25, 2021 5:18 pm

deleting routes script

Tue May 25, 2021 8:56 pm

PLEASE everyone i am trying to delete routes that appears twice on my routing table, i ran the following script to no avail ; really new to this stuff
:global countWan 0;
:while(/ip route find [comment="WAN1" dst-address=0.0.0.0/] do { :set countWan($countWan+1);}
:if ($countWan=0) do
{
/ip route add gateway= lte1 dst-address=0.0.0.0/0 comment="WAN1" }
else ={ :if ($countWan1>)1 {
/ip route remove [ find comment ="WAN1"]
}
}
 
User avatar
tomaskir
Trainer
Trainer
Posts: 1162
Joined: Sat Sep 24, 2011 2:32 pm
Location: Slovakia

Re: deleting routes script

Thu May 27, 2021 6:32 pm

Something like this should work (adjust as needed):
/ip route
:if ([:len [find comment="WAN1" dst-address=0.0.0.0/0]] > 0) do={
  :foreach i in=[find comment="WAN1" dst-address=0.0.0.0/0] do={
    remove $i
  }

  /ip route add gateway=lte1 dst-address=0.0.0.0/0 comment="WAN1"
}
Last edited by tomaskir on Fri May 28, 2021 4:47 pm, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: deleting routes script

Thu May 27, 2021 7:03 pm

:put [:typeof 0.0.0.0/ ] 
str
:put [:typeof 0.0.0.0/0 ] 
ip-prefix

Why appear twice the routes? Is the right question.
Disable add-default-route on lte profile, not?
I have rewrited the script, try to understand what you try to do.
/ip route
:global arrayWan [find where comment="WAN1" and dst-address=0.0.0.0/0]
:global countWan [:len $arrayWan]
:if ($countWan > 0) do={
  remove $arrayWan
} else={
  add gateway=lte1 comment="WAN1"
}

Who is online

Users browsing this forum: cmmike, hatred, MidnightKool and 39 guests