If I create a system script called NetwatchLog, which logs $id for example, it works if I set up the netwatch as such:
add ... up-script=NetwatchLog
However, it does not receive those variables in this format:
add ... up-script=/system script run NetwatchLog
I have a lot of code in that which I would like not to repeat. Any ideas? I tried a function global var but that doesn’t work because netwatch doesn’t allow access to global vars!
[$“done-tests”] etc should be ($“done-tests”) if you want to assign them . Square brackets are for commands only, so that your big problem — parenthesis () are for grouping & still need the rest ($“variable-with-space”).
Ah, yeah that was a mistake but the values still worked when this is placed in a netwatch itself.
I’ve updated to things like this, but they are still empty unless called as a “bare” script reference, not when called any other way.
:local done $"done-tests"
I really want to avoid repeating all this code over and over, but not sure how to do it. It seems the variables from netwatch will never propagate down to a called script unless referenced “bare”.
But for certain up/down on netwatch, I have it modify routes and kill connection tracked session, so I can’t call the script for those and have to repeat this… at least it is shorter.
Yeah the netwatch variable aren’t going to pass via a /system/script/run… The variables are already local to the netwatch script, so “passing” them another script isn’t going to work.
While you should be able to assign them to globals (or uses a single array global with the values), that’s not ideal either.
Another approach be to declare a global function that does the desired logging etc, and call that function from the netwatch with the $“done-tests”, etc network variables as parameters to a NetwatchLog function. The save copying code to each netwatch since /system/script/run does not take arguments (but functions “exported” by script do allow parameters).