Call parallel sql scripts from shell and return status when both sql are done

Hi Experts:

I have a shell script that's kicked off by cron. Inside this shell script, I need to kick off two or more oracle sql scripts to process different groups of tables. And when both sql scripts are done, I will continue in the shell script to do other things like checking processing time or error log, etc.

Can someone please give an example on this? To make the sqls run in parallel, do I need 1 running in the background? And how do I do that when calling sqlplus?

Your suggestions are very appreciated! Thank you!

HS

As if not parallel:

(
( script1 . . . ) >/tmp/$$.log1 2>&1 &
pid1=$!

( script2 . . . ) >/tmp/$$.log2 2>&1 &
pid2=$!

echo =================

wait $pid1
ret=$?
cat /tmp/$$.log1
rm /tmp/$$.log1
echo script1 returns $ret
echo =================
 
wait $pid2
ret=$?
cat /tmp/$$.log2
rm /tmp/$$.log2
echo script2 returns $ret
echo =================
) >>logFile 2>&1

I tried do this:

(command) &
pid=$!

but $pid is null. Does the command background job has to finish for pid to have a value? I need the command to be submitted in the background and running there, and the shell kicks off another background job that process in the background too.
This is my code:

{
  echo "$ORA_LOGIN"
  echo "@$file_name;"
} | sqlplus -silent >> test.log 2>&1 &
SQL1_PID=$!
echo "SQL1_PID is $SQl1_PID."

And the output is SQL1_PID is .

Why is that?

Thank you!

Change these lines:

SQL1_PID=$!
echo "SQL1_PID is $SQl1_PID."

to this -

echo "PID is $!"

tyler_durden