Community discussions

MikroTik App
 
mortar8
just joined
Topic Author
Posts: 21
Joined: Mon Sep 16, 2013 1:41 pm

Problem with accessing global variables between scripts

Mon Sep 16, 2013 2:28 pm

Hello.
I'm puzzled with this because as I have read, global variables should be accessible from any script of a user. Meanwhile I can assign a global variable in script, read it from terminal, but cannot read it from another script. Also, the variable is not listed in system/script/environment, but I am able to read it.
Here's the simplest proof :
[admin@Router] /system script> print                   
Flags: I - invalid 
 0   name="testput" owner="admin" 
     policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api 
     last-started=sep/16/2013 13:17:22 run-count=3 source=:put $testvar 

 1   name="testset" owner="admin" 
     policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api 
     last-started=sep/16/2013 13:17:19 run-count=4 source=:global testvar [/system clock get time] 
[admin@Router] /system script> /system clock print 
            time: 13:19:09
            date: sep/16/2013
  time-zone-name: Europe/Warsaw
      gmt-offset: +02:00
      dst-active: yes
[admin@Router] /system script> run testset
[admin@Router] /system script> run testput 
syntax error (line 1 column 7)
[admin@Router] /system script> environment print 
 # USER                               NAME                              VALUE                             
[admin@Router] /system script> /put $testvar 
13:19:19
My problem is with syntax error everytime I try to read global variable.
This doesn't happen when I set the var in the same script, with the same command as the other, so this is not an error in syntax. I have only one user.

Please help.
v6.1 on RB750GL
 
User avatar
TealFrog
just joined
Posts: 23
Joined: Sun Oct 02, 2011 11:56 am

Re: Problem with accessing global variables between scripts

Thu Sep 19, 2013 2:16 pm

Global variables should be declared before being used. Make sure not to specify a value or you will overwrite the existing value.
For example in the "testput" script:
:global testvar
:put $testvar
TealFrog

Who is online

Users browsing this forum: fmarais007 and 18 guests