0

I have a file containing IP address of 10 servers. e.g host.txt

I want to tar a directory and on 10 differents server from 1 server.

How can I run ssh parallel to those server which can reduce my exceution time

I have tried below code, but no luck.

cat host.txt |
 while read i
 do 
    ssh -qn $i 'tar -cvf /tmp/TC.tar.gz /etc' &
 done

Expectation:

Want to parallel SSH the 10server, so that the tar command will execute parallelly on server without using PSSH.

Akki
  • 21

1 Answers1

1

Use clusterssh: https://sourceforge.net/projects/clusterssh/

To execute commands in parallel, you use it like

cssh user@client1 user@client2

This you get a terminal window for each client and a commandwindow to type commands on any terminal in parallel.

There are many options to set inside ~/.clusterssh directory, so it is easy to group your clients by tags.

To bundle clients from your host.txt, the file ~/.clusterssh/tags may look like this:

root@host1 tar update
root@host2 tar update
root@host3 tar test
root@host4 update test
root@host5 update test

This way you define the tags tar, update and test. You can use the tag tar to run clusterssh on the first three hosts by running cssh tar.

Search the internet for clusterssh and you'll find a lot of helpful docs.

Most linux distros contain clusterssh so you may install it easily by e.g. apt-get install clusterssh.

Edit:

You may add your command to clusterssh to be executed use the -a option:

cssh tar -a "tar -cvf /tmp/TC.tar.gz /etc"

And if you use ssh public/private keys, you don't have to type the password all the time ...

ChristophS
  • 565
  • 5
  • 13