Reputation: 7064
I'm writing script which will be run from removable media but requires this media to be unmount during execution. It can't just do it straght because medium is busy then. Thus I've split script into 2 parts - one running before unmount which is copying second script part to ramfs and launching it, second part which is unmounting madia, doing job then self-deleting and unmounting creted ramfs. But the problem is that asynchronous script started in bash launches in foreground and I don't know how this script could bring itself programmatically foreground to get user input.
So i need something like this:
script1 does his job
script1 starts script2
script1 dies
script2 goes to foreground
script2 unmounts media with script1
script2 does his job
scirpt2 starting async command and dies
async command unmounts ramfs
Upvotes: 0
Views: 329
Reputation: 16138
You want wait
:
script1 &
JOB_SCRIPT1=$!
script2 &
JOB_SCRIPT2=$!
wait $JOB_SCRIPT1
echo "this action takes place after script1 but perhaps during script2"
wait $JOB_SCRIPT2
echo "now both jobs are complete"
async command unmounts ramfs
However, this doesn't seem to do exactly what you want; it appears that there are some background jobs spun up by script1
. That's harder to control for. Perhaps try wait
without arguments and see if that picks up the fact that there are backgrounded processes (but I'm dubious since they're not a part of the same shell):
script1 &
wait
script2
async command unmounts ramfs
(The ampersand in this version shouldn't actually do anything, but may cue the shell into what you want. You'll have to try it out to see.)
Upvotes: 1