Alex
Alex

Reputation: 315

Simultaneously execute two queries on a shell script

I have a shell script in which I have to execute two queries (on different databases), spool their results to text files and finally call a C++ program that processes the information on those text files. Something like this:

sqlplus user1/pw1@database1 @query1.sql
sqlplus user2/pw2@database2 @query2.sql

./process_db_output

Both queries take some time to execute. One of them can take up to 10 minutes, while the other one is usually faster. What I want to do is execute them simultaneously and when both are done, call the processing utility.

Any suggestion on how to do so?

Upvotes: 1

Views: 1644

Answers (1)

tdammers
tdammers

Reputation: 20721

Use & to background the queries, then wait to wait for all subprocesses to finish, and then the c++ thing that processes the results. Code:

 #!/bin/bash
 # first calling
 sqlplus user1/pw1@database1 @query1.sql &
 sqlplus user2/pw2@database2 @query2.sql &

 #now waiting
 wait
 #done waiting
./process_db_output

Upvotes: 6

Related Questions