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

1 Answer 1

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.

1
  • Thanks, the "return values" throw me off, as I was looking for exit code/status.
    – yellowhat
    Oct 12, 2021 at 17:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .