Hi,
i have a scheduler, the content is:
:global IPAddress [/ip address get [find interface=“$([/interface find type=bridge] name)”] address]
:for i from=( [:len $IPAddress] - 1) to=0 do={:if ( [:pick $IPAddress $i] = “/”) do={:global CustomerControl [:pick $IPAddress 0 $i]}}
/tool fetch mode=http port=80 address=10.5.5.11 url=“http://10.5.5.11/network/update/$CustomerControl.txt ”
if i direct copy and paste into new terminal, then there is no issue.
but when i put in the scheduler, then the …
/tool fetch mode=http port=80 address=10.5.5.11 url=“http://10.5.5.11/network/update/$CustomerControl.txt ”
will have an error, what happen on this???
mrz
January 29, 2013, 1:47pm
2
Do not define global variable in local scope if you intend to access it in another scope
http://wiki.mikrotik.com/wiki/Scripting#Local_scope
hi mrz,
i have no programming based and study one by one by still not understand,
would you mind to correct me and from there i can learn for it…
appreciated.
mrz
January 29, 2013, 2:02pm
4
This line
:for i from=( [:len $IPAddress] - 1) to=0 do={:if ( [:pick $IPAddress $i] = “/”) do={:global CustomerControl [:pick $IPAddress 0 $i]}}
you are defining global bariable CustomerControl inside :for scope, so this variable will not work outside for scope.
You need
:global CustomerControl;
…
:for i from=( [:len $IPAddress] - 1) to=0 do={:if ( [:pick $IPAddress $i] = “/”) do={:set CustomerControl [:pick $IPAddress 0 $i]}}
…
mrz:
This line
:for i from=( [:len $IPAddress] - 1) to=0 do={:if ( [:pick $IPAddress $i] = “/”) do={:global CustomerControl [:pick $IPAddress 0 $i]}}
you are defining global bariable CustomerControl inside :for scope, so this variable will not work outside for scope.
You need
:global CustomerControl;
…
:for i from=( [:len $IPAddress] - 1) to=0 do={:if ( [:pick $IPAddress $i] = “/”) do={:set CustomerControl [:pick $IPAddress 0 $i]}}
…
Dear Mrz…
It work now, appreciated and thanks for help…