Community discussions

 
ShyLion
newbie
Topic Author
Posts: 40
Joined: Thu Sep 28, 2017 7:24 am

Running script via API does not set global variable

Thu Aug 29, 2019 9:53 am

Hello. I'm strugling with task of getting lte info via API.
I've come with solution where global var is set via scheduled script and i fetch it's value with API call.
That is not perfect way, because information is obsolete by the time i fetch it and what is more important - it is absent when device is just rebooted and came online, but scheduled script didn't run yet.
Now to the subject.
I've tried to run mentioned script via API call, just vefore fetching it's result:
mktik_api_cmd -i 10.2.1.4 /system/script/run =.id=lteinfo
It's run count is increased, but variable value does not change!

Script itself:
[busadmin@r00004] > system script print detail where name="lteinfo"
Flags: I - invalid 
 0   name="lteinfo" owner="busadmin" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon dont-require-permissions=no last-started=aug/29/2019 11:49:02 run-count=19 
     source=:global lteinfo nointerface; if ([/interface lte print count-only] > 0) do={ :local li [/interface lte info lte1 once as-value]; :set lteinfo ("atech=".$li->"access-
       technology".";cop=".$li->"current-operator".";rs=".$li->"registration-status".";rssi=".$li->"rssi".";rsrp=".$li->"rsrp".";su=".$li->"session-uptime"); }; 

Formatted:
:global lteinfo nointerface;
:if ([/interface lte print count-only] > 0) do={
  :local li [/interface lte info lte1 once as-value];
  :set lteinfo ("atech=".$li->"access-technology".";cop=".$li->"current-operator".";rs=".$li->"registration-status".";rssi=".$li->"rssi".";rsrp=".$li->"rsrp".";su=".$li->"session-uptime");
}; 

What am i doing wrong?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5921
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Running script via API does not set global variable

Thu Aug 29, 2019 10:52 am

does it work with dont-require-permissions=yes?
 
ShyLion
newbie
Topic Author
Posts: 40
Joined: Thu Sep 28, 2017 7:24 am

Re: Running script via API does not set global variable

Thu Aug 29, 2019 10:56 am

does it work with dont-require-permissions=yes?
It only affects running script with non-owner user. Nothing changes in regard of problem, i tried.

Maybe i'm going wrong way? Maybe i can get result of [/some non api command] via script itself?
 
ShyLion
newbie
Topic Author
Posts: 40
Joined: Thu Sep 28, 2017 7:24 am

Re: Running script via API does not set global variable

Thu Aug 29, 2019 12:03 pm

Damn it!
Script, runnig via API, does not have access to "/interface lte info lte1 once as-value"
WTF?

Who is online

Users browsing this forum: No registered users and 7 guests