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
pssh -i -h list_of_hosts \
-x "-oStrictHostKeyChecking=no -i /home/xxx/.ssh/ec2.pem" 'uptime'