Re: Differentiating between ssh connection failures and ssh command failures

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

 



On Fri, 11 Sep 2015, Alex Bligh wrote:

> I'm sure this should be an easy question, but from the ssh client manpage:
> 
> EXIT STATUS
>      ssh exits with the exit status of the remote command or with 255 if an error occurred.
> 
> 
> Let's say I'm using
>     ssh server.example.com /usr/bin/do/something
> in (e.g.) a bash script.
> 
> How can one differentiate between a failure of ssh to connect to the host and the
> command in question returning an error? I need to detect both, and differentiate
> between them.

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

_______________________________________________
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