Hi, I would like to know if there is away to check the script name.
I mean I want to write log prefix “MyScriptName” (variable, I mean it’s will change when i’ll change name).
Hi, I would like to know if there is away to check the script name.
I mean I want to write log prefix “MyScriptName” (variable, I mean it’s will change when i’ll change name).
Just bumping this thread as I would also like to know if there is some way to get the current script name dynamically.
Something like the PHP magic constant FILE or
$_SERVER["SCRIPT_FILENAME"]
Is there anything like this in RouterOS scripting or can it be determined in some way?
Not exactly the answer, but instead of /import you could use a $import function. This way you could
also pass parameters to script file and return results.
:global import do={/import $1; return $result}
Create a script file demo.rsc
:if ($0 = "\$import") do={
:put "script name: $1"
:put "parameter msg: $msg"
:set $result ($msg="hello")
} else={
:put "cannot pass parameters with /import"
}
.. and see how it works:
[admin@rb4] /user> /import demo.rsc
cannot pass parameters with /import
Script file loaded and executed successfully
[admin@rb4] /user> :put [$import demo.rsc msg="Hi"]
script name: demo.rsc
parameter msg: Hi
Script file loaded and executed successfully
false
[admin@rb4] /user> :put [$import demo.rsc msg="hello"]
script name: demo.rsc
parameter msg: hello
Script file loaded and executed successfully
true