Hi all,
I am trying to run a server on one host, and have 3 clients located on 3 开发者_高级运维different hosts run at the same time (in the background).
I made a bash script to do that. The problem is that the script currently does not wait for the client to finish: it ssh on each host sequentially. I would like to have the 3 hosts run in parallel please.
Here is the code:
#!/bin/bash
i="0"
dir="~/bin/"
while [ $i -lt 3 ]
do
let number=10+$i
ssh sshost$number 'cd $dir && java Main &'
let i=$i+1
done
I am trying to ssh to 3 different hosts (number gets changed on each iteration), then go to the directory and type java Main. My only problem is that it won't do it in parallel, and I can't figure out how to fix it.
I would appreciate any help.
Thank you very much.
Make the ssh command to run in background:
ssh sshost$number 'cd $dir && java Main &' &
You can call wait
outside the while loop.
精彩评论