Community discussions

MikroTik App
 
Dude2048
Member Candidate
Member Candidate
Topic Author
Posts: 212
Joined: Thu Sep 01, 2016 4:04 pm

Script works from CLI but not from system scripts V7

Thu Jan 05, 2023 8:49 pm

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
 
User avatar
eworm
Forum Guru
Forum Guru
Posts: 1070
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Script works from CLI but not from system scripts V7  [SOLVED]

Thu Jan 05, 2023 10:24 pm

You need to declare the variable first:
:global bps;
/interface monitor-traffic ether2 once do={
:set bps $"rx-bits-per-second" }
:put $bps
 
Dude2048
Member Candidate
Member Candidate
Topic Author
Posts: 212
Joined: Thu Sep 01, 2016 4:04 pm

Re: Script works from CLI but not from system scripts V7

Thu Jan 05, 2023 11:30 pm

So stupid of me. I don't know why I missed this. Big thnx
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script works from CLI but not from system scripts V7

Fri Jan 06, 2023 1:47 am

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"
}
 
Dude2048
Member Candidate
Member Candidate
Topic Author
Posts: 212
Joined: Thu Sep 01, 2016 4:04 pm

Re: Script works from CLI but not from system scripts V7

Fri Jan 06, 2023 11:38 am

Thank you for the tips. I will try to better my life.

Who is online

Users browsing this forum: alexantao, maxslug and 31 guests