Community discussions

 
msteil
just joined
Topic Author
Posts: 12
Joined: Mon Nov 18, 2013 1:10 am

Testing to see if script is runing

Tue Jun 05, 2018 5:03 pm

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.
 
User avatar
dasiu
Trainer
Trainer
Posts: 232
Joined: Fri Jan 30, 2009 11:41 am
Location: Reading, UK
Contact:

Re: Testing to see if script is runing

Tue Jun 05, 2018 7:07 pm

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}
 
msteil
just joined
Topic Author
Posts: 12
Joined: Mon Nov 18, 2013 1:10 am

Re: Testing to see if script is runing

Tue Jun 05, 2018 7:31 pm

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.
 
User avatar
dasiu
Trainer
Trainer
Posts: 232
Joined: Fri Jan 30, 2009 11:41 am
Location: Reading, UK
Contact:

Re: Testing to see if script is runing

Tue Jun 05, 2018 11:08 pm

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.

Who is online

Users browsing this forum: No registered users and 22 guests