t777
t777

Reputation: 3329

SSH does not return exit code of last command

I exexcute

$ ssh remotehost "exit 1"
$ echo $?
0

The result is 0 and not 1.

I have read here on stackoverflow, that it should be 1. What is going wrong? TIA!


Update (Solution):

ssh is a function on that site, and there is one command executed after the ssh call.

Executing /usr/bin/ssh remotehost "exit 1", the exit-code is 1.

Thanks to @jeb :)

Upvotes: 0

Views: 33

Answers (1)

jeb
jeb

Reputation: 82390

Some hints to find such problems.

  • Check if the command is an alias or redirected:
    type ssh, which ssh or use \ssh remotehost "exit 1"
  • Check if your prompt modifies the exitcode:
    false followed by echo $? should output a 1
    echo $PROMPT_COMMAND shows if there is an user defined prompt function active, unset it
  • Check the command itself:
    ssh -vvv remotehost "exit 1" it should show the exitcode in the last debug line, something like debug1: Exit status 1

Upvotes: 1

Related Questions