3

I would like to use pdsh to assert that a command successfully run on multiple nodes, if the command fails on any nodes the exit code (from pdsh) should be non-zero.

Consider the following examples:

$ pdsh -w host1,host2 "exit 0"; echo $?
host1: host1
host2: host2
0
$ pdsh -w host1,host2 "exit 1"; echo $?
host1: host1: ssh exited with exit code 1
host2: host2: ssh exited with exit code 1
0
$ pdsh -w host1,host2,host3 "exit 1"; echo $?
host1: host1: ssh exited with exit code 1
host2: host2: ssh exited with exit code 1
host3: host3: ssh exited with exit code 255
0

The second example should return a non-zero exit code.

In the third example host3 does not exist and still the exit code is zero.

Am I missing something?

Thanks

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
yellowhat
  • 133
  • 4

1 Answers1

3

Use pdsh with its -S option.

From the manual:

-S
Return the largest of the remote command return values.

This would set the pdsh utility's own exit-status to the maximum exit-status of any of the commands executed on the remote hosts.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936