Community discussions

MikroTik App
 
CrazySaibot
just joined
Topic Author
Posts: 2
Joined: Sat Jun 16, 2018 1:43 pm

Script does not work at startup from /system script

Sat Jun 16, 2018 2:35 pm

Why if you run this script

:global a true
:global b true

:if ($a = true) do={:global InterfaceName "ether1"}

:if ($b = true) do={:global MacAddress [/interface ethernet get [find where name=$InterfaceName] mac-address]}

using command

/system script run <script id>

it does not work, and if you run this script

:global a true
:global b true

:if ($a = true) do={:global InterfaceName "ether1"}

:global InterfaceName $InterfaceName

:if ($b = true) do={:global MacAddress [/interface ethernet get [find where name=$InterfaceName] mac-address]}

using the same command

/system script run <script id>

does it work?

And if you run this script using copying and pasting into the terminal, both options work

This is bug?
 
User avatar
dasiu
Trainer
Trainer
Posts: 231
Joined: Fri Jan 30, 2009 11:41 am
Location: Reading, UK
Contact:

Re: Script does not work at startup from /system script

Mon Jun 18, 2018 3:22 pm

It's expected. Try reading about the "scopes" in the scripting manual - there is identical example.
https://wiki.mikrotik.com/wiki/Manual:S ... ocal_scope
Note that even variable can be defined as global, it will be available only from its scope unless it is not already defined.
 
CrazySaibot
just joined
Topic Author
Posts: 2
Joined: Sat Jun 16, 2018 1:43 pm

Re: Script does not work at startup from /system script

Mon Jun 18, 2018 8:33 pm

It's expected. Try reading about the "scopes" in the scripting manual - there is identical example.
https://wiki.mikrotik.com/wiki/Manual:S ... ocal_scope
Note that even variable can be defined as global, it will be available only from its scope unless it is not already defined.

Thanks! I understand! I did not think that in relation to the global this applies..

Who is online

Users browsing this forum: No registered users and 23 guests