It is not possible in the generic case. In some special cases it is, e.g. for a PPP-type interface.
The workaround is to make a script that is scheduled at some interval, and keep the previous status in a global variable.
You script compares the current status with the previous status in the global variable, acts accordingly, and finally copies the current status to the variable before it exits.
I'm seeking a solution for CRS switch devices with RouterOS in Bridge Mode (I think the procedure could be the same on router devices).
Code: Select all{ :local f [:tobool [:len $gArr]] :if ($f = false) do={ :global gArr [:toarray ""] :set ($gArr->"key1") "val1" } :put $gArr }
:if ([/system script environment find name=$shortName]) do={} else={[:parse "global $shortName 99"];};
This is a script installed under /system/script under a name "test".You can print in /system script environment.
Man, by print I really mean this ":put" function or command or how else it is called.I gave two answers to two questions.
In environment all globals live. If not there then it is not a global.
Why do you need print while you have put and set?
Is this documented somewhere?For your script it is known that tobool is broken since a long time.
In the said script ":put" is used, I just said "printing". But it's clear from the context what is meant.The print is a official command like put is. Print can do other stuff then put and they are used to their specific purpose.
Print is print and put is printing using put. Some things are just not straight forward.
As you noticed, it is not.What's new in 6.46beta44 (2019-Sep-19 05:54):
Changes in this release:
*) capsman - fixed channel auto reselection;
*) chr - added support for Azure guest agent;
*) console - fixed "tobool" conversion;
It is not what? Not fixed?As you noticed, it is not.What's new in 6.46beta44 (2019-Sep-19 05:54):
Changes in this release:
*) capsman - fixed channel auto reselection;
*) chr - added support for Azure guest agent;
*) console - fixed "tobool" conversion;
{
:set $f [:len $gArr]
:if ($f = "true") do={:set $f true} else={:set $f false};
:if ($f) do={} else={
:global gArr [:toarray ""]
:set ($gArr->"key1") "val1"
}
:put [:pick $gArr 0]
}
But it's a global variableYou initialize the variable inside a block, thus it's not visible outside.
{
{... :set $f [:len $gArr]
{... :if ($f = "true") do={:set $f true} else={:set $f false};
{... :if ($f) do={} else={
{{... :global gArr [:toarray ""]
{{... :set ($gArr->"key1") "val1"
{{... }
{...
{... :put [:pick $gArr 0]
{...
{... }
val1
:put [:pick $gArr 0]
val1
My code is correct, as it runs in RouterOS. $f is local . You don't have always to go through the process of defining it. It not Cobol.@msatter, stop please. Your code can't be correct as you use $f in the initialization...
{
:if ([/system script environment find name="gArr"]) do={} else={:global gArr [:toarray ""]; :set ($gArr->"key1") "val2";};
}
{
:put [pick $gArr]
}
:if ([/system script environment find name="gArr"]) do={:put $gArr;} else={:global gArr [:toarray ""]; :set ($gArr->"key1") "val2";};
:if ([/system script environment find name="gArr"]) do={:put $gArr;} else={:global gArr [:toarray ""]; :set ($gArr->"key1") "val2";};
key1=val2
You are not initializing it, you just change the value of an already existing variable.My code is correct, as it runs in RouterOS. $f is local . You don't have always to go through the process of defining it. It not Cobol.@msatter, stop please. Your code can't be correct as you use $f in the initialization...![]()
Sure, it is. But even global variables are accessible only...But it's a global variableYou initialize the variable inside a block, thus it's not visible outside.![]()
:global gArr;
{
:global gArr;
:if ([ :len $gArr ] = 0) do={
:set gArr [:toarray ""];
:set ($gArr->"key1") "val1";
}
:put $gArr;
}
:if ([/system script environment find name="gArr"]) do={} else={:global gArr [:toarray ""]; :set ($gArr->"key1") "val2";};
:global gArr;
:put $gArr;
{
if ([/system script environment find name="gArr"]) do={} else={global gArr [toarray ""]; set ($gArr->"key1") "val2"}
global gArr
put $gArr
}