Community discussions

MikroTik App
 
bonnecomm
newbie
Topic Author
Posts: 38
Joined: Sat May 30, 2009 8:29 am

Quiet scripting

Wed May 10, 2017 6:09 am

I haven't had this problem before so I'm asking for a bit of help. Here's my script so far:
:local tx;
:local rx;
/interface monitor [/interface find name="ether1"] once do={
:set tx $"tx-bits-per-second";
:set rx $"rx-bits-per-second"
};
put "{\tTxRate: $tx,\r\n\tRxRate: $rx\r\n}";

When I do "/system script run NetStatus", I'm getting the following result:
name: ether1
rx-packets-per-second: 118
rx-bits-per-second: 557.3kbps
fp-rx-packets-per-second: 0
fp-rx-bits-per-second: 0bps
rx-drops-per-second: 0
rx-errors-per-second: 0
tx-packets-per-second: 89
tx-bits-per-second: 68.8kbps
fp-tx-packets-per-second: 0
fp-tx-bits-per-second: 0bps
tx-drops-per-second: 0
tx-errors-per-second: 0
{ TxRate: 68872,
RxRate: 557312
}

I'm getting output from the monitor I don't want. How do I quiet that so I only get my formatted TxRate and RxRate?
Thx
 
User avatar
ahmedalmi
Frequent Visitor
Frequent Visitor
Posts: 75
Joined: Sat Sep 13, 2014 5:52 pm
Location: sana'a yemen
Contact:

Re: Quiet scripting

Sat May 13, 2017 4:06 am

try this

Code: Select all

{
:global tx;
:global rx;
/interface monitor [/interface find name="ether1"] once do={
:set tx $"tx-bits-per-second";
:set rx $"rx-bits-per-second"
};
put "{\tTxRate: $tx,\r\n\tRxRate: $rx\r\n}";
}
and you can use $tx, $rx "global" by any another script, or by new terminal, just write :put $tx;
 
bonnecomm
newbie
Topic Author
Posts: 38
Joined: Sat May 30, 2009 8:29 am

Re: Quiet scripting

Sat May 13, 2017 11:41 pm

What you gave me gives me the exact same problem I was complaining about.
/system script run script1
name: ether1
rx-packets-per-second: 244
rx-bits-per-second: 232.1kbps
rx-drops-per-second: 0
rx-errors-per-second: 0
tx-packets-per-second: 32
tx-bits-per-second: 38.0kbps
tx-drops-per-second: 0
tx-errors-per-second: 0
{ TxRate: 38000,
RxRate: 232160
}

This script, once it's done, will be run about once an hour from SSH by some custom monitoring software. I want a JSON object delivered to the monitoring software. What I'm getting is a bunch of extraneous text I don't want. I suppose I could :put "/* "; before I run the monitor command and :put " */"; after I run the command and before I put my rates, but that seems like an ugly kludge.
 
User avatar
ahmedalmi
Frequent Visitor
Frequent Visitor
Posts: 75
Joined: Sat Sep 13, 2014 5:52 pm
Location: sana'a yemen
Contact:

Re: Quiet scripting

Sun May 14, 2017 12:17 am

i gave you global value you can use it any time after run script by any way.

try to write :put $rx; in new terminal after run script , in new line
you will get just value what you want
 
bonnecomm
newbie
Topic Author
Posts: 38
Joined: Sat May 30, 2009 8:29 am

Re: Quiet scripting

Sun May 14, 2017 12:22 am

I suppose I could do that, have a script with ugly output run once a minute and set the globals I need, and then grab the globals from the script that is called by SSH. That might be the only workable solution. Thanks for the idea.
 
User avatar
ahmedalmi
Frequent Visitor
Frequent Visitor
Posts: 75
Joined: Sat Sep 13, 2014 5:52 pm
Location: sana'a yemen
Contact:

Re: Quiet scripting

Sun May 14, 2017 12:33 am

I suppose I could do that, have a script with ugly output run once a minute and set the globals I need, and then grab the globals from the script that is called by SSH. That might be the only workable solution. Thanks for the idea.
i hope this help you,
you welcome