My Octopress Blog

A blogging framework for hackers.

Running Sudo With Pssh

The pssh tool is great. Just great. At SEOmoz we use a number of deployment schemes, but every so often I find myself needing to log into 50 machines and perform some simple one-off command. I’ve written such a line many times:

1
for i in {01..05}; do ssh -t ec2-user@some-host-$i 'sudo ...'; done

This is fine if the command is quick, but it really sucks if it’s something that takes more than just a few seconds. So in the absence of needing to use sudo (and thus the -t flag), pssh makes it easy to run these all in parallel:

1
pssh -i --host=some-host-{01..50} -l ec2-user 'hostname'

Coercing pssh to create a pseudo-tty to enable sudo commands was a little tricky, though:

1
2
# And now I can sudo!
pssh -x '-t -t' -i --host=some-host-{01..50} -l ec2-user 'sudo hostname'