Differentiating between ssh connection failures and ssh command failures
alex at alex.org.uk
Sat Sep 12 19:29:43 AEST 2015
On 12 Sep 2015, at 03:13, Stephen Harris <lists at spuddy.org> wrote:
> On Sat, Sep 12, 2015 at 11:14:07AM +1000, Damien Miller wrote:
>> ssh server.example.com /usr/bin/do/something
>> if [ $r -eq 0 ] ; then
>> echo success
>> elif [ $r -eq 255 ] ; then
>> echo ssh failed
>> echo command failed
> ssh remoteserver exit 255
> Hmm :-)
> exit(-1) aka exit(255) is a pretty standard "generic failure code"
> for many programs.
That's *exactly* the issue I'm concerned about. Furthermore the server is
not UNIX so I have no idea how to wrap it in something that makes it
return a different exit code.
> The problem, really, is that "exit code" is the wrong thing to test for.
Well, I suppose there could be a CLI option to squash any non-zero
return codes from the remote into a single specified return code.
I don't think there is currently.
> x=`ssh remoteserver "echo CONNECTED && somecommand"`
> And then see if CONNECTED appears in the output to show successful
That's about as far as I got too. Technically that would fail to
differentiate between the shell being /bin/false and failure to
connect, but would be good enough for my use.
More information about the openssh-unix-dev