I need to call a script from the API and pass it a parameter (an IP). From what I understood, it is not possible to pass parameters to scripts, so, I declared and set a global variable ($IP) that the script uses. From an SSH session, this works well…
The problem is that I cannot find a way to set this variable from the API, while the documentation says it is possible, the API always returns a trap. The variable has been declared from an SSH session using the admin user and the API connection is using the admin user too.
but its content was empty (although it has been set to a non empty value from the SSH session).
So my questions are:
If it is possible to set a global variable through the API and call a script that uses this variable, how can I do with the API?
Is there a non documented way to call a script and give it some parameters? If there is not, does MikroTik plan to add this feature in the future?
Is there a workaround so I can pass an information to a script (not with a temp file because this script will be called often and writing to a file is slow IIRC)?
Both methods you used are the right way to set a value. To get a value though, you need to use “print” instead of “get” AND (more importantly for your question), you can only read those values from within the API, and not from script. Terrible, I know.
AFAIK, no. I too would like such a feature.
You could create a temporary script in “/system script” with the API, and write out the parameter as part of the source. While writing an “.rsc” file and “/import”-ing it is slow, writing a script in “/system script” and running it is not.