pssh (Parallel SSH) is a powerful tool if you need to manage multiple boxes. Originally developed by Brent Chun, it’s now maintained by Andrew McNabb.
Installation
Depending on your distro, you probably have pssh available in a repository of some sort. I know there’s a new version in the Fedora 12 yum repository and lots of binaries in RPM format. Since I was playing with a CentOS 5.4 installation, and pssh isn’t in the default repositories, I chose to grab the source from the new project home.
pssh is written in Python. Now, I don’t know the first thing about Python, but using ez_setup.py made the build and install exceedingly painless. (Follow the INSTALL notes in the tar file.)
Install setuptools, extract the source, and then build it:
$ wget 'http://peak.telecommunity.com/dist/ez_setup.py'
$ python ez_setup.py
$ tar -xvf pssh-2.0.tar.gz
$ cd pssh-2.0
$ python setup.py install
This will install the utilities to /usr/bin
Usage
$ pssh --help
usage: pssh [OPTIONS] -h hosts.txt command [...]
options:
--help show this help message and exit
-h HOST_FILES, --hosts=HOST_FILES
hosts file (each line "host[:port] [user]")
-l USER, --user=USER username (OPTIONAL)
-p PAR, --par=PAR max number of parallel threads (OPTIONAL)
-o OUTDIR, --outdir=OUTDIR
output directory for stdout files (OPTIONAL)
-e ERRDIR, --errdir=ERRDIR
output directory for stderr files (OPTIONAL)
-t TIMEOUT, --timeout=TIMEOUT
timeout (secs) (-1 = no timeout) per host (OPTIONAL)
-O OPTIONS, --options=OPTIONS
SSH options (OPTIONAL)
-v, --verbose turn on warning and diagnostic messages (OPTIONAL)
-A, --askpass Ask for a password (OPTIONAL)
-P, --print print output as we get it (OPTIONAL)
-i, --inline inline aggregated output for each server (OPTIONAL)
Configuration
Create a hosts file for pssh to act on.
$ more pssh_hosts.txt
# host[:port] [user]
192.168.5.10:12345 glen
192.168.5.11:12345 glen
Run
$ pssh -h /home/pssh_hosts.txt -P date
192.168.5.10: Wed Dec 30 03:44:40 GMT 2009
[1] 22:44:24 [SUCCESS] 192.168.5.10:12345
192.168.5.11: Wed Dec 30 03:42:22 GMT 2009
[2] 22:44:24 [SUCCESS] 192.168.5.11:12345
I’m not sure if I like the output from -P
or -i
better. I’ll have to play with both for a while.
To redirect the output to a file, use the -o
switch and give it a directory name. In the output directory will be files, named after each of your targets, containing the command results.
There is some old documentation still available at Brent Chun’s original site, but it could be out-dated. I know the binary install location has changed and the --help
switch has the newer options.
While playing with the 2.0 version from the Fedora 12 repo, I noticed the pscp
command is now pscp.pssh
. I couldn’t find any reference to why the change was made. The source I built from has the original pscp
command. (Update: I came across this comment referring to a name-clash with PuTTY’s scp utility.)
Note:
pssh assumes you have publickey–no password entry–access to all the machines you’re managing. To set that up, take a look at this.
Enjoy!