Saturday, February 12, 2011

What's pdsh and how it works?

What's pdsh?
Pdsh is a an efficient, multithreaded remote shell client which executes commands on multiple remote hosts in parallel. Pdsh implements dynamically loadable modules for extended functionality such as new remote shell services and remote host selection.
I.e., If you'd like to control multiple machines at once then you can use pdsh to reach it.
For example:
And I'd like to control node1 and node2 on Server1 at once.

1. Install pdsh on the Server.
2. Import ssh key of Server1 to the node1 and node2.
3. Add hostname-to-IPaddress of node1/node2 in /etc/hosts on Server1.
4. To execute: pdsh -w ssh:root@node[1,2] ls 2> /dev/null then node1 and node2 will to execute ls command and report to the Server1 as following:
lawrence@suse:~/.ssh> pdsh -w ssh:root@node[1,2] ls 2> /dev/null
node1: anaconda-ks.cfg
node1: Desktop
node1: install.log
node1: install.log.syslog
node2: anaconda-ks.cfg
node2: bin
node2: conf-examples
node2: cpulimit-1.1.tar.gz
node2: cpulimit.tar.gz
node2: Desktop
node2: install.log
node2: install.log.syslog
node2: mibs
node2: mibs_20100925.rar

5. Combine multiple commands:
lawrence@suse:~/.ssh> pdsh -w ssh:root@node[1,2] "cd /tmp;ls" 2> /dev/null
node1: pulse-Bk60xcI9xlDq
node1: virtual-root.pHV8bR
node2: etherXXXXWj7KYw
node2: gconfd-root
node2: keyring-RdVKdK
node2: mapping-root
node2: scim-panel-socket:0-root

No comments: