4.0RC1 refresh problem ?

Playing around trying to determine the LAN gateway, I stumbled across something weird. Imagine ether1-gateway connected to the LAN, and ether3-local-slave connected to another device that acts as a backup gateway.

Run this script :

while (true) do={
:put [/ip route get number=0 gateway]
:delay 3
};

then pull the plug on ether1-gateway. The info displayed will not reflect the new gateway unless you do an
/ip route print
in between !

Similar : Create a new script from Winbox, say this is item 4. When from console you do :
/system script edit 4 source, you get a no such item, unless you perform a /system script print first. Am I missing something ?

yes, when using scripting you can’t directly reference an item number because it could change. You should use ‘find’ to find the item you want.

while (true) do={
:put [/ip route get [/ip route find gateway=“0.0.0.0/0”] gateway]
:delay 3
};

or something like that.

Hmm I was hoping I could since when you pull the plug on one interface, the new gateway will become item 0 again.

The best I managed to come up with sofar to find the gateway(s) is something like this :

:local i
:foreach i in=[/ip route find dst-address=“0.0.0.0/0”] do={
:put [/ip route get $i gateway]
};

Now hopefully this does not crash the script with a no such item when I pull the plug.

It does not explain the create script example though, you have to /system script print first before you can edit.

The numerical ID isn’t the true ID of the item. The numerical ID gets created on request, such as during a print command.