4

There are a few things going on here but I think ultimately, either CLish or SSH is returning an exit code that is messing up my work flow.

I'm attempting to connect to a remote machine (CLish shell) using sshpass. The script that is being run is exiting with "exit 0" (and works when I call it directly on my local machine) but the exit code that is returned to my local shell is "255". Yes, confusing, I know, but maybe an example will help. I think I've narrowed down my problem to a simple example.

Connect to server running CLish and drop to bash shell in single command from local machine to server:

me@local$ sshpass -p 'password' ssh -t [email protected] 'shell'
user@server:~$ exit 0
exit
Connection to 172.16.5.4 closed.

Back on my machine, check the exit code:

me@local$ echo $?
255

Manually drop to shell on the remote machine with sshpass and CLish:

me@local$ sshpass -p 'password' ssh [email protected]
CLishPrompt> shell
me@server$ exit
exit
CLishPrompt> exit
Connection to 172.16.5.4 closed.

Check the exit code back on my machine:

me@local$ echo $?
0

I really need to issue the 'shell' command in the same sshpass call as in the first example because I am using redirection to write a script to the server's filesystem and run it (all in a single call). I would like it to return an exit code of "0" like the second example shows. I have been unable to find a work-around this problem. The reason I need exit code "0" is because this script is returning its findings in a Jenkins-CI "build" and I don't know how to tell Jenkins-CI to accept an exit code of 255. If this was bash, then I could check the exit code myself and continue on to the next part of my script.

I need to either get ssh to return "0" or tell Jenkins that "255" is okay in this instance. Do you know what's going on here or have any suggestions?

5
  • Obvious solution^W workaround: write a bash wrapper script, then you can test the return code.
    – derobert
    Commented Apr 16, 2013 at 21:38
  • Obvious solution^W workaround: use public key authentication instead of a password. Commented Apr 16, 2013 at 23:34
  • It's part of a CI thing and public key auth isn't an option at this time. I have added a wrapper which is a great workaround. I guess having jenkins accept other codes is a long, slippery slope that I shouldn't go down but I'm curious as to why the different return codes on the two different methods. It's quite unexpected. Commented Apr 17, 2013 at 12:20
  • I don't know CLish at all, but I do notice a difference: in the second (manual) case you provide commands shell and eventually exit to CLish; in the first case CLish apparently exits because after shell the code ends. What if you provide exit as well? Can you do it? I don't know the right syntax, like shell; exit maybe, or the two commands with a literal newline character between them. Commented Aug 9, 2022 at 11:26
  • That's a good observation; however, I'm far removed from that environment now and have no desire to recreate that setup. I think the solution was to create a wrapper script but I'm coming to that conclusion because of my comment above. I honestly don't recall. Commented Aug 9, 2022 at 13:13

0

You must log in to answer this question.

Browse other questions tagged .