Sel*_*vel 7 scripting mikrotik
我在 RB493G 上安装了 RouterOS 5.14。我需要编写脚本,启动
/tool fetch ...
Run Code Online (Sandbox Code Playgroud)
执行 fetch 可能会导致错误,这是可以的(URL 有时可能不可用)。脚本因错误而挂起。有什么办法可以忽略它吗?
解决方案:
[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"
}
Run Code Online (Sandbox Code Playgroud)
警告:使用了未记录的 ":execute"。
您现在可以do使用错误处理程序创建一个块:
:do {
/tool fetch $url
:put "Fetch OK"
} on-error={ :put "Fetch ERROR"};
Run Code Online (Sandbox Code Playgroud)