Page 1 of 1

Testing to see if script is runing

Posted: Tue Jun 05, 2018 5:03 pm
by msteil
Hello All,

I am attempting to verify that a given script is not already running before attempting to start it so I don't inadvertently get multiple instances running at the same time.

My attempt is as follows:

:local SCRIPT "script1"
:local RUNNING [/system script job get [/system script job find where script=$SCRIPT] script]
:if ([:len $RUNNING] = 0) do={/system script run $SCRIPT}

What I have works correctly as long as the script is running, but if the script is not running what I have terminates prematurely at the end of line 2 with the output of "no such item".

Also, is there a way to run my script in line 3 that would allow the script being called, to run in the background and allow the startup script to terminate? In other words like starting a Linux process with the "&"

Thanks for the input.

Re: Testing to see if script is runing

Posted: Tue Jun 05, 2018 7:07 pm
by dasiu
Simplify it a bit - and it will work :)
:local SCRIPT "script1"
:local RUNNING [/system script job find script="$SCRIPT"]
:if ([:len $RUNNING] = 0) do={/system script run $SCRIPT}

Re: Testing to see if script is runing

Posted: Tue Jun 05, 2018 7:31 pm
by msteil
Thanks, forgot the KISS principal.. Any input on the second aspect, on how to call script "B" from script "A" but yet allow script "A" continue and ultimately terminate allowing script "B" continue to process? Again much like starting a process in the background in Linux? Example "Command &"

Best regards.

Re: Testing to see if script is runing

Posted: Tue Jun 05, 2018 11:08 pm
by dasiu
Partially only. Use:
:execute "/system script run $SCRIPT";
The execute will be in background, parent script will run till the end independently, but still will be visible on scripts list as it is the parent.