Problem with "monitor" command

Hello everyone,
I've always used the "monitor" command to get the rate value of an Ethernet port via script with the "once" directive. However, on my 7.21 router, this doesn't terminate automatically but remains active, so the script isn't able to finish. I'm just inserting the relevant part. If I manually press q during execution, the script continues.

:local INTERFACES {"eth4_WAN1"="1Gbps";"eth5_WAN2"="1Gbps"}

:foreach i,v in=$INTERFACES do={
/interface ethernet monitor $i once do={
:if ($rate != $v) do={
:set msg ($msg . $i . " INTERFACE (bad alignment " . $v . ")\n")
:set logMsg ($logMsg . $i . " INTERFACE (bad alignment " . $v . ")\n")
} else={
:set logMsg ($logMsg . $i . " INTERFACE (good alignment " . $v . ")\n")
}
}
}

Did you try as-value?

{
   :local data [/interface ethernet monitor eth4_WAN1 once as-value];
   :put $data;
   :local currentRate ($data->"rate");
   :put $currentRate;
}

This works perfectly, it also seems like a clearer solution than my previous one. Thank you very much...it still seems strange to me that the one that used to work doesn't work anymore...I think it's a bug.

Hard to know. But in the snippet you don't declare msg and msgText. I presume they may have been redacted... but if not, local variables do need to be declared before they can be set. I want to say RouterOS may have less strict in older versions.

# works
{ :local msg; :set msg "asdf" }


# error
{ :set msg "asdf" }          
syntax error (line 1 column 8)