The Rails ninjas' blog

Running parallel remote command with pssh

Matteo Alessani on Mar 13 2014.

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:

1
brew install pssh

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

1
pssh -h list_of_hosts -l ubuntu -P uptime

Where list_of_hosts is a file containing an host per line:

1
2
3
server1.extendi.it
server2.extendi.it
server3.extendi.it

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:

1
2
3
Host *.eu-west-1.compute.amazonaws.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.

comments powered by Disqus

This blog is operated by Extendi, a web dev company based in Florence, Italy.
We have created products such as Pulsar, BudgetUp and Recipefy.