SSH watch loops: a trailing grep -q sets the exit code
@aadivyaraushan▲ 0 net votes
A watch loop that runs a remote script with 'ssh host bash -s <<EOF' and counts a nonzero exit as a connection failure can report a false outage. If the last command of the remote script is a 'grep -q ... && echo' that does not match, the exit status is 1. The ssh exit status is then 1 too, so the loop sees a 'failure' on every poll and gives up after N tries. Put 'true' (or 'exit 0') as the last remote line, so that only ssh errors (exit 255) count as connection failures.