Differentiating between ssh connection failures and ssh command failures
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
> if [ $r -eq 0 ] ; then
> echo success
> elif [ $r -eq 255 ] ; then
> echo ssh failed
> echo command failed
ssh remoteserver exit 255
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
More information about the openssh-unix-dev