Unix shell script run SQL scripts in parallel

橙三吉。 提交于 2020-01-13 04:47:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!