Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 user@172.16.5.4 '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 user@172.16.5.4
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?

share|improve this question
    
Obvious solution^W workaround: write a bash wrapper script, then you can test the return code. –  derobert Apr 16 '13 at 21:38
    
Obvious solution^W workaround: use public key authentication instead of a password. –  Gilles Apr 16 '13 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. –  harperville Apr 17 '13 at 12:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.