Return value to a variable

Since RouterOS v6.43 it is possible to save the result of fetch command to a variable. For example, it is possible to trigger a certain action based on the result that a HTTP page returns. You can find a very simple example below that disables ether2 whenever a PHP page returns "0":

{
:local result [/tool fetch url=http://10.0.0.1/disable_ether2.php as-value output=user];
:if ($result->"status" = "finished") do={
:if ($result->"data" = "0") do={
/interface ethernet set ether2 disabled=yes;
} else={
/interface ethernet set ether2 disabled=no;
}
}
}


:global abc [/tool fetch url="http://realip.uhaozu.com" mode=http as-value output=user]



:put ($abc->"data")

58.240.251.12

:put ($abc->"status")

finished

ros从6..43版本允许把fetch返回来的数值引入变量data去使用。_php

 

 

多了一个全局变量abc,可以在后面引用出来使用。