The pdsh command is a parallel version of the dsh (Distributed Shell). It is used to run commands on multiple remote hosts in parallel and supports a number of remote shell programs including SSH.
Cheat sheet[edit | edit source]
Depending on your pdsh install, it may default to rsh rather than ssh. Pass in
-R ssh to change the default module.
|List all installed modules|
|Use a specific module. Eg. SSH|
|Connect to a certain nodes with a specific module|
|Run a command on all hosts|
|Run a command on all hosts EXCEPT one|
|Run a command on a set of hosts by hostname
Or by a specific gender (ie. attribute), see below.
|Collect the OS version on all hosts and group it|
Installation[edit | edit source]
You can install pdsh from the epel repo.
# yum -y install epel-release # yum -y install pdsh pdsh-rcmd-ssh
Alternatively, install from source from the GitHub repo at: https://github.com/chaos/pdsh
Modules[edit | edit source]
pdsh -L to list all remote command modules available.
You can see the default module that will be used when running
SSH remote module[edit | edit source]
For SSH support, you will need to install the
pdsh-rcmd-ssh package. Additional SSH arguments can be passed by passing in the PDSH_SSH_ARGS_APPEND environment variable. Eg:
# PDSH_SSH_ARGS_APPEND=”-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=error” pdsh -a uptime
Configuration[edit | edit source]
Genders file[edit | edit source]
The genders file can be used to give attributes to nodes in a cluster. It can be thought of as groups that can be used as a target when running pdsh commands. While the genders file isn't required, it's still a good idea to have set up because it allows the
-a option to function properly.
The genders file is usually located at
/etc/genders. Each line can contain one or more hosts and attributes are given as a comma delimited list. Here is an example genders file:
ca-controller management ca-login cluster-a,login ca[001-168] cluster-a,cpus=4 cb-login cluster-b,login cb[091-320] cluster-b,cpus=8
Using this example, you can target:
- Only the control node with
pdsh -w management
- Only cluster A nodes with
pdsh -w cluster-a
- Only nodes with 8 CPUs with
pdsh -w cpus=8
See also[edit | edit source]
- Libgenders man page talks about using genders and target grouping - https://linux.die.net/man/3/libgenders