I'm using Amazon Linux with bash shell. I would like to run a couple of processes in the background, and then wait for them to complete (either with a success or error exit code) before proceeding. So I tried:
node test.js 2>&1 | tee --append $TFILE1 &
proc1=$!
node SkyLocal.js 2>&1 | tee --append $TFILE2 &
proc2=$!
wait proc1
rc1=$?
wait proc2
rc2=$?
but I'm getting these errors:
/home/jboss/.jenkins/jobs/myproject/workspace/automated-tests/nodejs/run_tests.sh: line 36: wait: `proc1': not a pid or valid job spec
/home/jboss/.jenkins/jobs/myproject/workspace/automated-tests/nodejs/run_tests.sh: line 38: wait: `proc2': not a pid or valid job spec
How do I capture the PID of the background process and then wait for the process to complete before continuing?
wait $proc1
Don't forget the dollar sign.