When I create a script like below, in works like a charm in CLI but the “put” command stays empty when I run it from system scripts. Is this a V7.6 bug?
:interface monitor-traffic ether2 once do={:global bps $"rx-bits-per-second" }
:put $bps
When I create a script like below, in works like a charm in CLI but the “put” command stays empty when I run it from system scripts. Is this a V7.6 bug?
:interface monitor-traffic ether2 once do={:global bps $"rx-bits-per-second" }
:put $bps
You need to declare the variable first:
:global bps;
/interface monitor-traffic ether2 once do={
:set bps $"rx-bits-per-second" }
:put $bps
So stupid of me. I don’t know why I missed this. Big thnx
If you use correct syntax, is more easy.
Better call “:interface” as “/interface”
I do not think you need the bps variable globallly…
If the method support “as-value” you do not need to use more complex “do={}”
On CLI you must use { at the start and at the end } because each line do not keep local variables.
On script the start { and the end } are not needed.
ether2 is not one variable, but is one string, better use " "
There are a lot of things that still work even if written badly, but sometimes they give unexpected results,
and if one has gotten used to writing incorrectly, he can’t even find the errors…
{
:local bps ([/interface monitor-traffic "ether2" once as-value]->"rx-bits-per-second")
:put $bps
}
Or for better structure the script for future mods:
{
:local iface "ether2"
/interface
:local tmparr [monitor-traffic $iface once as-value]
:local rxbps ($tmparr->"rx-bits-per-second")
:local txbps ($tmparr->"tx-bits-per-second")
:put "$iface bps RX $rxbps / TX $txbps"
}
Thank you for the tips. I will try to better my life.