I have RouterOS 5.14 on RB493G. I need to write script, that launches

/tool fetch ...

Execution of fetch may result in error, this is OK(URL may be sometimes unavailable). Script hangs on error. Is there any way to ignore it?


[admin@Mikrotik] >> /system script
0 name=safe-fetch source=
:global done
:global url

/tool fetch $url
:Set done=true

1 name=test source=
:global done
:global url="google.com"

:set done false
:execute safe-fetch
:local counter 0
:while ( $done != true && $counter < 10 ) do={
    :set counter ($counter+1)
    :delay 0.2

if ($done = "true") do={
   :put "Fetch OK"
   } else={
   :put "Fetch ERROR"

Warning: not documented ":execute" is used.


It seems that there isn't error handling in this kind of scripts. You should probably adopt the solution proposed by this guy:

So you have to have 2 scripts, one that runs and does stuff and handles situation when some value is not received as expected, and other script does the job, that can fail. as a result, if second script fails, first one that called second script to do the job will continue.

  • 1
    Thank you, this works. Mikrotik scripts are very poor and crooked :( – Selivanov Pavel May 27 '12 at 0:55
  • 1
    "You may award your bounty in 6 hours." - the bounty will be yours tomorrow. – Selivanov Pavel May 27 '12 at 1:03
  • I've added :delay to reduce processor load with empty cycle – Selivanov Pavel May 27 '12 at 1:04

UPDATE as of RouterOS v6.2

You can now create a do block with an error handler:

:do {
  /tool fetch $url
  :put "Fetch OK"
} on-error={ :put "Fetch ERROR"};
  • 1
    Finally, they added error handling. Thank you, @Old-pro ! – Selivanov Pavel Jun 21 '17 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.