Results 1 to 4 of 4
Hi all,
I have a script that calls another program/script, xxx, to run in the background. Supposedly this program at most should finish within five (5) minutes so after five ...
- 03-27-2011 #1Just Joined!
- Join Date
- Oct 2009
- Posts
- 10
Problem running a program/script in the background from a script
Hi all,
I have a script that calls another program/script, xxx, to run in the background. Supposedly this program at most should finish within five (5) minutes so after five (5) minutes, I run some other steps to run the script into completion.
My problem is sometimes the program takes longer than five (5) minutes and this is causing problems when running the rest of the steps in the scripts. Can anyone suggest how to re-program my script.
At the moment, the KSH script, i.e. test.ksh, is doing as below:
test.ksh:
....
....
xxx/xxx.ksh <--- program/script called by the script
sleep 300
..... run the rest of the script ......
...... problem is sometimes xxx/xxx.ksh takes longer than 300 seconds ......
...... any way that I can monitor that xxx/xxx.ksh finishes before I run ......
...... the rest of the scripts ......
Any advise will be much appreciated. Thanks in advance.
- 03-27-2011 #2Just Joined!
- Join Date
- Mar 2011
- Posts
- 4
Hi,
You could write the shell to await a valid return value before continuing. Better than default 5 minutes. If it completes in 2 minutes, it will continue on immediately ...
Using bash instead of ksh I wrote this shell:
Code:#!/bin/bash echo "beginning"; $?="1" #$? is the value of returned function, zero means successful. I set to one for this example while [ $? -ne 0 ] do ./test2.sh done echo "returnvalue is $? do something else..."; exit
- 03-27-2011 #3Linux Newbie
- Join Date
- Dec 2009
- Posts
- 241
You can save the procid after starting the script and check if it is still running.
Code:xxx/xxx.ksh <--- program/script called by the script procID=$! while ps -p $procID > /dev/null; do sleep 10 done ---- next commands
- 03-27-2011 #4
Why are you running the script in the background? The whole point of running a script in the background (with rare exceptions) is that you don't care when it finishes.
DISTRO=Arch
Registered Linux User #388732


Reply With Quote