I have 3 shell scripts, Script1,Script2 and Script3. Now I want to run Script1 and Script2 in parallel and Script3 should depend on successful completion of both Script1 and Script2.
Could you please suggest an approach of acheiving this...
simple polling approach (this master script itself may not run parallel, vulnerable to symlink attacks through unsafe tmp file creation, ...)
#!/bin/bash
# should work in most shells
(script1; echo $? > /tmp/retval1 ) &
script2
# both do now run in parallel
# ...
# well, after some time script2 will have finished, so well have to check whether 2 also has
retval2=$?
while [ $? -eq 0 ]
do
sleep 1s
pidof script1 > /dev/null
done
retval1=`cat /tmp/retval1`
if [ something about retval1 and retval2 ]
then
script3
fi