I had an issue where an ssh loop script was exiting after 1 host.
The fix use the -n flag.
Ensure ssh isn’t reading from standard input by using the -n option:
ZFSHEALTH=`/usr/local/bin/ssh -n $MACHINE "/sbin/zpool get health rpool" | grep ONLINE | wc -l`