How to handle Exception in the script Microtrik?

Mikrotik RouterOS v6.17
a piece of iron 2011UiAS-2HnD

the line from the script
:local InterfaceISP2Address [/ip address get [find interface=ether2] address]

If the interface has no address (the connection is broken, the problem is with dhcp server, etc. problems) the script fails with "no such item" and then fails.

How to make script to run on, despite "no such item"?
September 26th 19 at 06:26
2 answers
September 26th 19 at 06:28
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 ""
} else={
 # Get current IP address for the interface
 :set InterfaceISP2Address [ :tostr [ /ip address get [/ip address find interface=$interfaceName] address ] ]
September 26th 19 at 06:30
Try something like this:

:if ( [/ip address find interface=ether2 ] != "" ) do={\
 :local InterfaceISP2Address [/ip address get [find interface=ether2] address];\

Good luck!

Find more questions by tags Mikrotik