1

I have a Server implemented in Java named Provider, and linux script to start it.

#!/bin/bash
echo "Provider"
$JAVA_HOME/bin/java -cp /tmp  Provider&
$JAVA_HOME/bin/java -version
rm  /tmp/pid
echo "$!"> /tmp/pid
echo "Provider-finish"
exit 0

When I want to execute the following script at different machine (machine2)

root@machine1:/tmp# ssh  machine2/tmp/runScript.sh
Provider
java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
Java HotSpot(TM) Client VM (build 20.4-b02, mixed mode, sharing)
Provider-finish
Waiting for connection

The problem is that after running above script, it does not return console, it hang-up though Provider gets started.

I have analized similar concepts like Glassfish domain starting. by executing

ssh machine2 asadmin start-domain

it returns console without any problem so I can get execution status "$?"

1 Answer 1

2

I think that the problem is that the remote sshd won't close the ssh session because there is still a java process running in the background that might try to write output.

Try redirecting the background processes stdout and stderr to "/dev/null"; e.g.

$JAVA_HOME/bin/java -cp /tmp Provider > /dev/null 2>&1 &
Sign up to request clarification or add additional context in comments.

1 Comment

You are right, since java process tries to write outout sshd does not close ssh session. It is somehow understood when running same script locally. I have forwarded java process output to /dev/null as you suggested problem has been solved. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.