Edgar Cole
asked on
How to make a Korn shell script wait for a background job to finish
I have a Korn shell script which calls a Bourne shell script which runs a Cache database process. From memory, the Cache command looks something like this:
csession TEST -U something goes here ^ZBKCRON
The calling order looks like this:
Korn-shell-script --> Bourne-shell-script --> Cache-command
The problem is that I need for the Korn shell script to wait for the csession command to finish before it terminates. Unfortunately, it does not. I've tried using the wait command, to no avail. Under the circumstances, I don't think the $! variable would be of much use. The shell's ampersand operator (&) is not being used to put the csession command in the background, so if that's what's happening, I have no idea how.
csession TEST -U something goes here ^ZBKCRON
The calling order looks like this:
Korn-shell-script --> Bourne-shell-script --> Cache-command
The problem is that I need for the Korn shell script to wait for the csession command to finish before it terminates. Unfortunately, it does not. I've tried using the wait command, to no avail. Under the circumstances, I don't think the $! variable would be of much use. The shell's ampersand operator (&) is not being used to put the csession command in the background, so if that's what's happening, I have no idea how.
There is something you aren't telling us.
If you have
then the bash script won't output 'End' until the cession script has finished.
If you have
#!/bin/bash
csession TEST -U something goes here ^ZBKCRON
echo End
then the bash script won't output 'End' until the cession script has finished.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This was difficult to implement, because the corresponding processes were difficult to identify and isolate. Under the circumstances, however, it was the only viable solution. The primary difference between this example and what I ultimately implemented is that I dispensed with the timeout (i.e., the waitcount).
Alternatively if the csession process has been forked, the cleanest solution would be to alter the bourne shell to return the PID of the backgrounded csession, which you could trap and wait for, failing that the forked process will have the bourne shell's PID as it's PPID, so just find and wait for a process with that PID to end e.g.
Open in new window