controlling console output from script

I’m using SNMP to pull the results from a script on a Mikrotik and for simple stuff it is working great. However, when I want to do something a little more complex I’m having trouble controlling the output of the script to just output the final result.

I have a script like this:

:put ([/interface ovpn-server print count]-[/interface ovpn-server print count where name~"test"])

which returns the following:

[admin@TestRouter] > /system script run test
4
3
1
[admin@TestRouter] >

The result of 1 is correct (4-3), but I don’t want the 4 and 3 printed as everything that is printed gets returned to the snmp query (which is not so useful).

Is there a way to print only the final result instead of each element?

I have tried a few different things but none of them worked for me. I also tried searching for this but haven’t been able to find the answer. I was not sure of a short way to describe it so searching was hard.

print is for print, and if is used… print.


:put ([:len [/interface ovpn-server find]]-[:len [/interface ovpn-server find where name~"test"]])

or more logically better:

:put [:len [/interface ovpn-server find where (!(name~"test"))]]

Well that makes sense! Thanks rextended!