Differentiating between ssh connection failures and ssh command failures
Stephen Harris
lists at spuddy.org
Sat Sep 12 12:13:59 AEST 2015
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
More information about the openssh-unix-dev
mailing list