Friday, February 1, 2008

pdsh - rsh to multiple remote systems

A useful tool, specially when you are working with multiple systems/servers is pdsh. A variant of rsh, where it runs the command on multiple remote systems. And it does this smart where it fans out sending the command (multiple threads) so that we are not waiting for timeouts on some connections if that happens.

The man page is fairly detailed, and the impressive feature is that the command accepts host lists in general format (Its not really regular expressions, but does the job effectively. ) I can do the following:

[rutul@rutul-laptop]#pdsh -w 10.35.74.[66-72] ls
10.35.74.72: anaconda-ks.cfg
10.35.74.72: bin
10.35.74.71: ssh: connect to host 10.35.74.71 port 22: Connection refused
10.35.74.69: ssh: connect to host 10.35.74.71 port 22: Connection refused
10.35.74.66: anaconda-ks.cfg
10.35.74.66: Desktop


Pressing ctrl-c once shows status of all the connections:

pdsh@rutul-laptop: interrupt (one more within 1 sec to abort)
pdsh@rutul-laptop: (^Z within 1 sec to cancel pending threads)
pdsh@rutul-laptop: 10.35.74.67: command in progress
pdsh@rutul-laptop: 10.35.74.68: command in progress
pdsh@rutul-laptop: 10.35.74.70: command in progress

and another ctrl-c within one second aborts:

sending SIGTERM to ssh 10.35.74.67 pid 8161
sending SIGTERM to ssh 10.35.74.68 pid 8162
sending SIGTERM to ssh 10.35.74.70 pid 8164
pdsh@rutul-laptop: interrupt, aborting.

Very useful if you spend some time working on clusters and are clever at scripting.

No comments: