问题
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:
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
来源:https://stackoverflow.com/questions/18200727/unix-shell-script-run-sql-scripts-in-parallel