I am using Amazon Linux on AWS. Trying to execute a remote command using ssh like this:
% ssh somehost echo Hello World
@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@
<ECHO IS NOT EXECUTED HERE>
% echo $? # last exit code
0
This is something I expect (no need to fix the warning, failure is by design). However, I need to know if my remote command executed. Problem is ssh exit code is 0, and my remote command is dynamic and can, in principle, output the same text (if, say, it tries to execute another remote command on its own, or reads some log file).
So how do I tell if SSH failed to connect in that case?