How to get data from print with a parameter, eg. 'print rate'

Hi,
to get max limit of a queue I use this:

:foreach iname in=[/interface find where running] do={
  :local ifname [/interface get $iname name]
  :put [/queue tree get ("qos_" . $ifame)  max-limit]
}

How can I gate current rate?
In Terminal I would use ‘print rate’ to get a table. But how to get the rate value in a script?

Doesn’t

:put [/queue tree get ("qos_" . $ifame) rate]

work?

In general, “get” gives you the value you’d otherwise see on screen with a “print”… There have been exceptions though. Is that one of them (I don’t use queue trees…)?


At any rate (pun intended), you can also use print’s as-value argument, coupled with “from” if you want only a particular item, e.g.

:put (([:pick [/queue tree print from=("qos_" . $ifame) rate as-value] 0])->"rate")

or if the above breaks down (because scripting can sometimes be buggy like that…):

:local rates [/queue tree print from=("qos_" . $ifame) rate as-value];
:local ratesFirstMatch [:pick $rates 0];
:put ($ratesFirstMatch->"rate")

or if you want all rates:

:local rates [/queue tree print rate as-value];
:foreach item in=$rates do={
    :put ($item->"rate");
}
:put [/queue tree get ("qos_" . $ifame) rate]

ends with no such item.

But this code works perfectly! I didn’t know about getting data from print in script in a such way.

:put (([:pick [/queue tree print from=(“qos_” . $ifame) rate as-value] 0])->“rate”)

Thank you!