# set up services mkdir service svc0 svc1 svc2 svc2/log catexe svc0/run <<< """ #!/bin/sh echo svc0 ran >> output """ catexe svc1/run <<< """ #!/bin/sh echo svc1 ran """ catexe svc1/log <<< """ #!/bin/sh exec cat > output """ catexe svc2/run <<< """ #!/bin/sh echo svc2 ran """ catexe svc2/log/run <<< """ #!/bin/sh exec cat > ../output """ ln -s $(pwd)/svc[0-9] service/ svscan $(pwd)/service >svscan.log 2>&1 & setvar svscanpid = "$BgPid" while not svok svc0 && svok svc1 && svok svc2 && svok svc2/log { sleep 1 } # stop svscan and clean up kill $svscanpid wait >/dev/null 2>&1 svc -dx svc[0-9] svc2/log while svok svc0 || svok svc1 || svok svc2 || svok svc2/log { sleep 1 } head -n 1 svc[0-9]/output cat svscan.log rm -r svc0 svc1 svc2 service