Stephen Harris
2015-Sep-12 02:13 UTC
Differentiating between ssh connection failures and ssh command failures
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 > fissh remoteserver exit 255 Hmm :-) exit(-1) aka exit(255) is a pretty standard "generic failure code" for many programs. The problem, really, is that "exit code" is the wrong thing to test for. x=`ssh remoteserver "echo CONNECTED && somecommand"` And then see if CONNECTED appears in the output to show successful connection. -- rgds Stephen
Alex Bligh
2015-Sep-12 09:29 UTC
Differentiating between ssh connection failures and ssh command failures
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 >> 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
Darren Tucker
2015-Sep-12 13:29 UTC
Differentiating between ssh connection failures and ssh command failures
On Sep 12, 2015 7:30 PM, "Alex Bligh" <alex at alex.org.uk> wrote:> 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.Use the control master / mux function in the ssh client? That way the connection establishment and command requests will be separate invocations and you can check their return codes independently.
Markus Friedl
2015-Sep-18 12:57 UTC
Differentiating between ssh connection failures and ssh command failures
true. but never found this to be a problem in practice?> Am 12.09.2015 um 04:13 schrieb Stephen Harris <lists at spuddy.org>: > > 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. > > The problem, really, is that "exit code" is the wrong thing to test for. > > x=`ssh remoteserver "echo CONNECTED && somecommand"` > > And then see if CONNECTED appears in the output to show successful > connection. > > -- > > rgds > Stephen > _______________________________________________ > openssh-unix-dev mailing list > openssh-unix-dev at mindrot.org > https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev