Scripting distance of routes

I would like to get the distance of a route for scripting purpose.

something like :

if([/ip route get “distance of a route”] = 5 ) do={
:log error “distance is 5”;
}

but i can’t get any command that provides me a distance of a route.

BUMP

Try this:

:if ([/ip route get [find <your_search_criteria_goes_here>] distance] = 5) do={
    ...
}

This does not work.

Tried the following :

:if ([/ip route get [find gateway=x.x.x.x] distance] = 3) do={
    :log error "test2"
}

It keeps logging test2, no matther what distance i put in the if/else statement.

Spacing maybe!?!? This works for me:

:if ([/ip route [find gateway=x.x.x.x] distance]=2) do={:log error “True”}

This also does not work for me.

Is x.x.x.x a unique ID or do you have multiple with gateway=x.x.x.x?

Copy and paste the following in Terminal:

/ip route add dst-address=1.2.3.4/32 gateway=1.2.3.4 distance=5;
:if ([/ip route get [find gateway=1.2.3.4] distance]=5) do={:put "True"} else={:put "False"};
##Should have output of "True" since distance is 5;
/ip route set [find gateway=1.2.3.4] distance=6;
:if ([/ip route get [find gateway=1.2.3.4] distance]=5) do={:put "True"} else={:put "False"};
##Should have output of "False" since distance is 6;
:if ([/ip route get [find gateway=1.2.3.4] distance]=6) do={:put "True"} else={:put "False"};
##Should have output of True since IF/ELSE and distance is 6;

Should look like this!
route_distance.PNG

Indeed this works on my main Mikrotik, but not on the other one.
When running this , i get “invalid internal item number”

This worked for me :

:if ([/ip route get [:pick [find gateway=x.x.x.x] 0] distance]=1) do={:put “True”} else={:put “False”}

this because i had multiple routes with the same gateway as you guys said.

Thanks !