A
A
Alexander Matkovsky2014-07-30 10:59:12
Mikrotik
Alexander Matkovsky, 2014-07-30 10:59:12

How to handle Exception in Microtrik scripts?

Mikrotik RouterOS v6.17
piece of iron 2011UiAS-2HnD
line from the script

:local InterfaceISP2Address [/ip address get [find interface=ether2] address]

If the interface has not been assigned an address (connection failure, problem with dhcp server, etc.), then the script returns " no such item " and is not executed further.
How to force to execute a script further, despite "no such item"?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dannyzubarev, 2014-07-30
@Slyer

For example, like this:

:local interfaceName "ether2"
:local InterfaceISP2Address 

:if ([ :len [ /interface find name=$interfaceName ] ] = 0 ) do={
    :log warning "[SCRIPT_NAME] No interface '$interfaceName' was found, please do check updater script configuration."
    :set InterfaceISP2Address "0.0.0.0/0"
} else={
    # Get current IP address for the interface
    :set InterfaceISP2Address [ :tostr [ /ip address get [/ip address find interface=$interfaceName] address ] ]
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question