Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

run two shell scripts in one at same time?

Status
Not open for further replies.

mmcds

MIS
Jul 5, 2007
28
US
I am trying to run two shell scripts at once only in one script to kick it off on linux.

For example, below is what I do in my kick off script, which is called (startupdatedb.sh).

#!/bin/ksh

ssh userdb@app3 'cd /scripts/oss/ && ./updatedb.sh'
ssh userdb@app1 'cd /scripts/oss/ && ./updatedb.sh'



I want both updatedb.sh scripts on my 2 different servers (app1 and app3 to run at the same time. Right now, it will run the script on app3 first, I have to wait and then it will run the script on app1 and then it completes. I want to be able to have it run both updatedb.sh scripts at the same time. This is not a scheduled cron script either. It will be manually kicked off. I'm kind of lost on how to accomplish this or if there is a way.

Any help would be appreciated. Thanks!
 
I'm kind of lost on how to accomplish this or if there is a way.

Yes, place the ampersand character at the end of the line. eg:
ssh userdb@app3 'cd /scripts/oss/ && ./updatedb.sh' &

to make the first job run in 'backgroud' while you run:
ssh userdb@app1 'cd /scripts/oss/ && ./updatedb.sh'

and wait for the app1 script to finish.

Put the '&' character at the end of both, and the prompt is returned so that you can do something else.


I hope that helps.

Mike
 
If you want the calling script to wait till both called scripts finish, you can do this...
Code:
#!/bin/ksh

ssh userdb@app3 'cd /scripts/oss/ && ./updatedb.sh' &
ssh userdb@app1 'cd /scripts/oss/ && ./updatedb.sh' &

wait
It won't go on till both have completed.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top