Parallel remote "shelling" via pdsh

Ever have a multitude of hosts you need to run a command (or series of commands) on?  We all know that forloop outputs are super fun to parse through when you need to do this, but why not do it better with a tool like pdsh.
A respected ex-colleague of mine made a great suggestion to start using pdsh instead of forloops and other creative make shift parallel shell processing.  The majority of my notes in this blog post are from him.  If he’ll allow me too, I’ll give him a shout out and cite his Google+ profile for anyone interested.
Pdsh is a parallel remote shell client available from sourceforge.  If you are using rpmforge CentOS repos you can pick it up there as well, but it may not be the most bleeding edge package available.
Pdsh lives on sourceforge, but the code is on google:
Usage docs:
Some quick tips on how to get started using pdsh:
  1. Set up your environment:
  2. export PDSH_SSH_ARGS_APPEND=”-o ConnectTimeout=5 -o CheckHostIP=no -o StrictHostKeyChecking=no” (Add this to your .bashrc to save time.)
  1. Create your target list in a text file, one hostname per line (in the examples below, this file is called “host-list”
  2. It would probably be a good idea to use “tee” to capture output.
    • man tee” if you need more information on tee.
  3. Run a test first to make sure your pdsh command works the way you think it will before potentially doing anything destructive:
    • sudo pdsh -R ssh -w ^host-list “hostname” | tee output-test-1
  4. Change your test run to do what you really want it to after a successful test.  e.g.:
    • sudo pdsh -R ssh -w ^host-list “/usr/bin/mycmd args” | tee output-mycmd-run-1
Obviously if you have Puppet Enterprise fully integrated within your environment, you can take advantage of powerful tools such as mcollective.  If you do not, pdsh is a great alternative.
Advertisements