ssh exit_status not 255 for many errors

Tom Brown tdbrown at uiuc.edu
Tue May 31 21:27:14 EST 2005


Hello openssh developers,

I'm having some trouble with ssh version 3.8.1p1 but see the same
problem in the source I just pulled from
openssh at anoncvs.at.openbsd.org:/cvs

The man page for ssh says...
     ssh exits with the exit status of the remote command or with 255
		 if an error occurred.
thus I expect ssh to always return either 255 or the exit value of the
remote command but it frequently returns other values.

I want it to return 255 when it cannot connect, for example in this
case:
$ ssh -v -o ConnectTimeout=5 tdbrown at paypal.com echo hi
OpenSSH_3.8.1p1, OpenSSL 0.9.7e 25 Oct 2004
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to paypal.com [216.113.188.64] port 22.
debug1: connect to address 216.113.188.64 port 22: Connection timed out
debug1: Connecting to paypal.com [216.113.188.34] port 22.
debug1: connect to address 216.113.188.34 port 22: Connection timed out
ssh: connect to host paypal.com port 22: Connection timed out
$ echo $?
1  <-- Return value of ssh


The following fixes my problem

--- openssh-3.8.1p1/ssh.c       2005-05-26 13:25:16.000000000 -0700
+++ openssh-3.8.1p1.mine/ssh.c  2005-05-26 13:24:51.000000000 -0700
@@ -579,7 +579,7 @@
            original_effective_uid == 0 &&
options.use_privileged_port,
 #endif
            options.proxy_command) != 0)
-               exit(1);
+               exit(255);

        /*
         * If we successfully made the connection, load the host
         * private key

but `grep exit\( *.c` (both in 3.8.1p1 and cvs ssh.c -r1.255) reveals that
ssh frequently returns 1 instead of 255 when it has an error. Is this
considered by design or a bug? 

I only found a problem with scp incorrectly outputting 0 or >0 when
searching for "exit" in Bugzilla. Do you think any scripts that call
ssh depend on the specific >0 value it returns? I want to write a
script that can easily and reliably differentiate between when the remote
command has exit status 1 and the command not being run.

Thank you for considering my question,
Tom

-- 
Tom Brown   tdbrown at uiuc.edu




More information about the openssh-unix-dev mailing list