2

Disclaimer: I'm a bit new to the community, please be gentle :)

I'm having an SSH issue that I just can't seem to explain. As a bit of background, here's the problem that I'm solving:

There are several disparate Java services that existing within the environment that need to be deployed via a common interface. Logging of these services must be directed to a syslog facility. The common interface must be accessible via the command line and via the Jenkins GUI.

Where I started seeing problems was when I added redirection to the syslog. If I remove the syslog redirection, everything works fine. Here's a snippet of code that is called to execute the Java processes (scrubbed for readability):

/bin/java myJavaProgram -DvariousFlags=true &> >(logger -p local3.info -t "my prefix") 2>&1 &

Here's where my mind gets a bit boggled - if I run the command that calls these scripts from the server that Jenkins is on as the Jenkins user, the command works. If I run it through the Jenkins GUI, the job just hangs. I'm running the following command in Jenkins:

ssh -t jenkins@appserver.example.com 'appctl restart all' 2>/dev/null

I've confirmed with the #!/bin/bash -x flag that the script is reaching its end. When I run with the ssh -vvv, the following is the last line of output:

debug1: client_input_channel_req: channel 0 rtype exit-status reply 0

Any thoughts on where to go from here? Is there a better way of accomplishing the syslog feature? Is something wrong with my piping?

3

Logger is likely not forking into to the background, so SSH thinks you still have a process open and doesn't close the connection.

Try adding 2>/dev/null >/dev/null </dev/null inside the quotes for your appctl command so that all the filehandles are closed at the top level.

  • Thanks! Marked your answer is correct. However, I wanted to maintain output in the Jenkins console. I posted my approach as an answer. Any idea why that solution worked? I've never redirected the standard outputs in that manner... – cerberus Feb 9 '17 at 16:55
3

Jason's answer is correct for the question I asked. However, I neglected to mention that I wanted to maintain the appctl output in the Jenkins console.

Jason prompted me to revisit the redirection. What I came up with is this:

ssh -t jenkins@appserver.example.com 'appctl restart all 1>&2'

Seems as though redirecting stdout to stderr makes SSH happy...

  • 1
    Perhaps it was only STDERR causing the hang, so redirecting it to STDOUT solves it. – Jason Martin Feb 9 '17 at 21:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.