[Solved] Running scripts in parallel that issue prompt

Hi all - I am totally stuck here :wall
I have been asked to write a shell script that does a few little things and then reads from a config file and kicks off an instance of another script, say scriptB.ksh for each line in the config file. These should all be run in parallel. This is all fine but scriptB.ksh prompts the user to confirm they want to proceed. I thought I had this handled with a here document but the problem is the instances of scriptB.ksh don't run in parallel then anymore. I do not own scriptB.ksh, its a shared script, I cannot change it, I cannot clone it...bottom line I have to work with it somehow.
Here is (one version!) what I have so far though I have experimented with moving the & around etc:

#!/usr/bin/ksh

IFS='|'
set -o xtrace

CONFIG=/home/testing/release.config

while read varA varB varC varD varE
do
        LOGFILE=release_`echo $varA`_`echo $varB`_`date '+%d%y%m_%H%M'`.log
        scriptB.ksh -j$varA -v$varB -i$varC -S$varD -D$varE <<!
c
!
> $LOGFILE 2>&1 &
        PIDS=$PIDS" "$!
done <"$CONFIG"

wait $PIDS

Would really appreciate any help - I am so long looking at it now I can't see any fresh leads!

Try..

while read varA varB varC varD varE
do
        LOGFILE=release_`echo $varA`_`echo $varB`_`date '+%d%y%m_%H%M'`.log
        scriptB.ksh -j$varA -v$varB -i$varC -S$varD -D$varE << ALWAYS_SAFE  > $LOGFILE 2>&1 &
	c
ALWAYS_SAFE
	PIDS=$PIDS" "$!
done <"$CONFIG"

You can use the "dashed" label to indent the heredoc (ONLY with tabs and NOT spaces).

like

while read varA varB varC varD varE
do
        LOGFILE=release_`echo $varA`_`echo $varB`_`date '+%d%y%m_%H%M'`.log
        scriptB.ksh -j$varA -v$varB -i$varC -S$varD -D$varE <<-ALWAYS_SAFE  > $LOGFILE 2>&1 &
	c
	ALWAYS_SAFE
	PIDS=$PIDS" "$!
done <"$CONFIG"

Also, by default, wait without any argument, would wait for all the background jobs.

1 Like

clx - thank you so much! I was totally overthining it and as a result was never going to find a result. Tested and running away in production as we speak - thank you, thank you, thank you!

BTW, reason I am passing pids to wait is that I kick off another (continuous) process in the background at the start of the script and I want it to run until all the scriptB processes are finished and then I kill it. As a result if I don't pass pids the continuous process would be included and the wait would never return.
I was just trying to cut down the sample code.

1 Like