Skip to content

Instantly share code, notes, and snippets.

@carlessanagustin
Last active June 1, 2016 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlessanagustin/c5e70c8edfa8408547545e26b61ab783 to your computer and use it in GitHub Desktop.
Save carlessanagustin/c5e70c8edfa8408547545e26b61ab783 to your computer and use it in GitHub Desktop.
Running parallel remote command with pssh

Method 1:

If you need to run the same command on multiple servers you can use a very useful tool called pssh. You can install it with Homebrew running:

brew install pssh

Once installed you can run the following command to get the current uptime on multiple server:

pssh -h list_of_hosts -l ubuntu -P uptime

Where list_of_hosts is a file containing an host per line:

server1.extendi.com
server2.extendi.com
server3.extendi.com

The option -l let you specify the user to login on the server and -P option let you see the output of the command you're going to run on your console. There are also other arguments you can pass to pssh. Check them with pssh --help.

If you want to login with your public key you cannot pass it to pssh as an option but you have to specify it on your ~.ssh/config file:

Host *.extendi.com
    StrictHostKeyChecking no
    IdentityFile ~/.ssh/ec2.pem

This is my configuration to login in EC2 instances where I have to use my ec2.pem file. The option StrictHostKeyChecking no prevent the failure of the command due to SSH's host verification for known hosts.

from: http://www.extendi.it/blog/2014/3/13/24-running-parallel-remote-command-with-pssh

Method 2:

pssh  -i  -h list_of_hosts  \
-x "-oStrictHostKeyChecking=no  -i /home/xxx/.ssh/ec2.pem" 'uptime'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment