Community discussions

MikroTik App
 
SumNathan
just joined
Topic Author
Posts: 8
Joined: Tue May 07, 2019 2:44 am

controlling console output from script

Mon Jun 28, 2021 10:04 am

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.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: controlling console output from script

Mon Jun 28, 2021 10:53 am

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"))]]
 
SumNathan
just joined
Topic Author
Posts: 8
Joined: Tue May 07, 2019 2:44 am

Re: controlling console output from script

Tue Jun 29, 2021 3:42 am

Well that makes sense! Thanks rextended!

Who is online

Users browsing this forum: abbio90, diamuxin and 14 guests