Community discussions

MikroTik App
 
BigAlambic
just joined
Topic Author
Posts: 4
Joined: Wed Apr 01, 2020 9:44 am

Global var empty when scripting, but exist in terminal.

Sun Nov 01, 2020 8:29 am

Hello!
I have a script to grab some LTE data. And result of this script is var. And I can see it int ":env print" or ":put $var". But I want to ask my SNMP this var with this method https://wiki.mikrotik.com/wiki/Manual:S ... s_with_GET. And I'm stuck. Don't understand how to output global var in script.
Script to make var $at:
/system script
add dont-require-permissions=no name=at owner=admin policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=\
    "/interface lte info lte1 once do={:global at \$\"access-technology\" } \r\
    \n"
Script to output it:
/system script
add dont-require-permissions=no name=at_result owner=admin policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=":put \$at"
And this is result:
[admin@Mikrotik_24] > /system script run at
           pin-status: ok
  registration-status: registered
        functionality: full
         manufacturer: "MikroTik"
                model: "R11e-LTE"
             revision: "MikroTik_CP_2.160.000_v008"
     current-operator: MTS
                  psc: 295
                  lac: 5205
       current-cellid: 241903616
    access-technology: 3G
       session-uptime: 21h3m18s
                 imei: 355654090621868
                 imsi: 250016652966098
                 uicc: 89701011266529660988
               earfcn: 10762
                 ecno: 0dB
                 rssi: -95dBm
 [admin@Mikrotik_24] > :environment print   
at="3G"

[admin@Mikrotik_24] > :put $at 
3G       


But, how to output it via script I don't know.
[admin@Mikrotik_24] > /system script run at_result     

[admin@Mikrotik_24] > 
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1873
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Global var empty when scripting, but exist in terminal.  [SOLVED]

Sun Nov 01, 2020 1:21 pm

Here is two way to set a global variable:
{
:global test
set $test "my data"
}
{
:global test "my data"
}
This will not work in a script to get the variable in a script, may work from terminal:
{
:put $test
}
You need to declare the variable in the script so it knows about it, so correctly:
{
:global test
:put $test
}
 
Why do not use Splunk to monitor your MikroTik Router(s)? Look at this page in how to set it up.

MikroTik->Splunk
 
 
BigAlambic
just joined
Topic Author
Posts: 4
Joined: Wed Apr 01, 2020 9:44 am

Re: Global var empty when scripting, but exist in terminal.

Sun Nov 01, 2020 3:09 pm

Thanks a lot Jotne!
Yes, you are right.
And via SNMP I can see this var even with my wrong {:put $var} in script.
snmpget -c public -v 2c 192.168.88.1 1.3.6.1.4.1.14988.1.1.18.1.1.2.2
SNMPv2-SMI::enterprises.14988.1.1.18.1.1.2.3 = STRING: "Evolved 3G (LTE)"
 
User avatar
SiB
Forum Guru
Forum Guru
Posts: 1314
Joined: Sun Jan 06, 2013 11:19 pm
Location: Poland

Re: Global var empty when scripting, but exist in terminal.

Mon Nov 02, 2020 2:29 pm

Maybe you will be insterested in Logging changes at LTE Parametrs to know if the Tower or Sector Antenna was change etc..
Watch LTE parameters: viewtopic.php?f=7&t=155945&p=821262#p821047
MTCNA + MTCRE + MTCINE | ~600 users at ~150 RouterBoards in EMEA | Telegram: @SiB_PL
WinBox Tip: F6 works as ALT+TAB | Gliffy.com - free network schematic | prnt.sc - free ScreenShot software
At vacation until 15.jan.2021

Who is online

Users browsing this forum: No registered users and 22 guests