How can I trigger multiple remote shell scripts in bash to run concurrently and then wait for them to complete? -
i have bash script runs number of tasks on remote machines via ssh. each script quite long i'd run them concurrently background tasks. need them finish before moving on. know can utilize wait command latter when stick & @ end create background task, stops working.
by stop working, mean scripts don't seem have run, otherwise main script still completes.
ssh root@machine1 'bash -s' < script1 my_parameter ssh root@machine2 'bash -s' < script2 my_parameter ssh root@machine3 'bash -s' < script3 my_parameter wait some_other_task
this works fine me ubuntu 11.04:
#!/bin/bash ssh user@server1 <command.sh & ssh user@server2 <command.sh & ssh user@server3 <command.sh & wait echo end
content of command.sh:
sleep 5 hostname
update:
with commandline arguments gets more complicated. can utilize "here-document" , set
set $1 $2 $3.
#!/bin/bash ssh -t root@server1 << eof #!/bin/bash set -- $my_parameter1 $my_parameter2 $my_parameter3 $(cat script1) eof ssh -t root@server2 << eof #!/bin/bash set -- $my_parameter1 $my_parameter2 $my_parameter3 $(cat script2) eof ssh -t root@server3 << eof #!/bin/bash set -- $my_parameter1 $my_parameter2 $my_parameter3 $(cat script3) eof wait echo end
bash shell ssh concurrency
No comments:
Post a Comment