Would you use a persistant interpreter variables registry?
- Yes, I think this is very helpful
- No, I dont need this
- I can see the value of this
- There are other ways.
Hi,
I am trying to write scripts that rely on global variables at times.
However, I find the scripts aren’t able to fetch or rely on globals due to some form of application isolation or environment partitioning.
Example:
I have a web service which I can use to report that my device is online.
The device requires a unique ID which we give it.
I have put these values in a script.
Included is the web host name we want the device to call back, and its identity values. This script is called “global-identity.rsc”
:global callbackHost "service.ourhost.com";
:global CID "80B3AB80-D895-4188-9811-752FBD129FB5";
:global SID "C5819D29-398A-4C15-8554-10DB8FBD96C3";
Now, I have various pieces of script which relies on this data.
Here’s a simple example.
This script is to download other script fragments from our service. It relies on the ‘callbackHost’ variable.
This script is called “downloader.rsc”
#script begin
/import global-identity.rsc
:log info "\n";
:log info "-------------------------------------------";
:log info "- Installing Mikrotik Script Packages -";
:log info "-------------------------------------------\n";
:local segmentList [ :toarray "01-ntpserver.rsc,07-watchdog-queue-choke.rsc,08-chokecontrol.rsc" ]
:local filePath "/provider/";
:foreach serverFile in=$segmentList do={
:log info "Downloading file section $serverFile";
:local thisFile ($callbackHost . $filePath . $serverFile);
/tool fetch dst-path=$serverFile url=$thisFile;
:log info "Importing file section $serverFile";
/import $serverFile
}
This does not work. I can put log outs/puts into the global-identity.rsc, and it will show the global variables being set, and values from them being printed.
However, in downloader.rsc which did the request, the globals are not set.
I’ve tried this example using the :parse method, and loading the file content into a variable, and parsing it in the context of downloader.rsc. Same deal.
This also happens when in /system script contexts as well.
I’m wondering if I could request some kind of flash persistent variable store object in the interpretor namespace
like something of the following:
/system variable add name=‘my_persistant_value’ value=‘some_value’ expires=never
then I can fetch them, from any script context using something like:
/system variable get my_persistant_value value
This would be amazing.
The reason why I ask for this, is our script features library now exceeds over 20 script routines, which rely on these unique variable values to be available, and when running, they have to be manually edited for each device.
Ultimately, we’re working on automatic device configuration, and as such the number of scripts is only set to grow higher as time passes.
– Pepin