3

How do I setup this KornShell (ksh) script to run SQL scripts 2,3 in parallel after tst1.sql is done then run tst4.sql after 2,3 are complete? Is this possible?

#/usr/bin/ksh
#SET ENVIRONMENT ORACLE

sqlplus user1/pw @/home/scripts/tst1.sql
sqlplus user1/pw @/home/scripts/tst2.sql
sqlplus user1/pw @/home/scripts/tst3.sql
sqlplus user1/pw @/home/scripts/tst4.sql
exit 0

1 Answer 1

3

The first command should run synchronously...

If you start the two last commands as background processes (add & at the end of the command), they will run in parallel.

Do you want the script to wait for the two last processes to be complete before leaving?

Something like this should work:

  sqlplus user1/pw @/home/scripts/tst1.sql
  sqlplus user1/pw @/home/scripts/tst2.sql &
  pid2=$!
  sqlplus user1/pw @/home/scripts/tst3.sql &
  pid3=$!
  # pseudo-code:
  # while (`ps -p"$pid2,$pid3" | wc -l` != "1");
  sqlplus user1/pw @/home/scripts/tst4.sql
Sign up to request clarification or add additional context in comments.

7 Comments

Yes. I want to wait. I also want to add another tst4.sql to run after 2,3 are complete. Is that possible?
Why don't you just concat tst2.sql and tst3.sql into some file (tmp.sql) that you would execute sync after tst1.sql and tst4.sql? Unless these files are very big (Gb), that is the easiest solution you'll have...
Can you please elaborate on how to use sync? No files are very small.
I meant synchronously. When you run 'sqlplus user1/pw @/home/scripts/tst1.sql', the script doesn't move to the next line before that process is complete... Why are you trying to run tst2 and tst3 in parallel? ... Do you really want 2 concurrent processes hitting the db?
need to run 2,3 in parallel to finish job faster then once that's complete, run last sql.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.