As it doesn’t appear to be possible to pass arguments directly to scripts, when a script references the variables from the caller (e.g. $“caller-id”, $user) are these specific to that invocation, or global in which case they may be changed by another on-up which occurs before the first has completed? i.e. what happens if another PPPoE client connects whilst the script for the original PPPoE connection has not yet completed execution.
Also, if using an array as a list which may have entries added and removed by more than one script, or script instance, are any operations atomic or is it possible the variable may be changed elsewhere part-way though a statement, e.g. when adding an item
:global things
:local item “somedata”
:set things ($things,$item)
or when removing an item
:global things
:local item ($things->0)
:set things [:pick $things 1 9999]
I do not see the problem:
on the on-up must be writed exactly, only, without any space, “;”, quotes or “return”, the name of the script (and not /system script run before)
the script must have dont-require-permissions, and all other permissions set.
All the parameters like $“caller-id”, $user, etc. are usable LOCALLY inside the script, are not global.
If multiple instance are launched, each instance have it’s own locally defined variables.
Working inside this script, except for circumventing restricted permission, is like exactly write inside the on-up field.
And each job are separate for another.
Obviously if you use :global variable inside one job, is shared among all jobs, but if happen, is your faut use “global” on useless way.
Using global variables is neither a ‘fault’ nor ‘useless’, given that Mikrotik scripting has no primitives to handle lists or queues of objects (note this has nothing to do with address/interface lists or interface/simple queues).
In this case the object is to update a third-party system when a PPPoE connection is established, and given the inefficiencies of Mikrotik scripting / response time of the third-party system (the script can take several seconds to complete) I would like to have a small script which adds the PPPoE on-up session variables to a list, the main script then processes each list item sequentially. If there are a lot of new PPPoE sessions at the same time, for example resulting from a power cut affecting clients or a DFS event on a radio link, I don’t particularly want dozens of instances of the script running at the same time.
For anyone with a similar use case… After some experimentation a global associative array works - the key is unimportant, it just has to be unique (to prevent collisions / data being overwritten) and increasing (to guarantee the earliest entries are processed first as arrays are sorted by key).