Re: Differentiating between ssh connection failures and ssh command failures

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

 



On 12 Sep 2015, at 03:13, Stephen Harris <lists@xxxxxxxxxx> wrote:

> On Sat, Sep 12, 2015 at 11:14:07AM +1000, Damien Miller wrote:
>> ssh server.example.com /usr/bin/do/something
>> r=$?
>> if [ $r -eq 0 ] ; then
>> 	echo success
>> elif [ $r -eq 255 ] ; then
>> 	echo ssh failed
>> else
>> 	echo command failed
>> fi
> 
> 
> 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
> connection.

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.

-- 
Alex Bligh




_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@xxxxxxxxxxx
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev



[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux