The following ssh command does not return to terminal. It hangs though the execution is completed. The execution hangs after echo hi command.
ssh user@testserver "echo hello;source .profile;source .bash_profile;/apps/myapp/deploytools/ciInstallAndRun.sh; echo hi"
Output
hello <outoutfrom remote script" hi
ciInstallAndRun.sh
echo 'starting' cd /apps/myapp/current ./tctl kill cd /apps/myapp mv myapp_v1.0 "myapp_v1.0_`date '+%Y%m%d%H%M'`" unzip -o /apps/myapp/myappdist-bin.zip java -classpath .:/apps/myapp/deploytools/cleanup.jar se.telenor.project.cleanup.Cleanup /apps/myapp myapp_v1.0_ 3 cd /apps/myapp/myapp_v1.0 echo 'Done with deploy' chmod -R 775 * echo 'Done' ./tctl start test
Source OS: Redhat Dest Os: Solaris 10 8/07
Any idea to fix this.
Advertisement
Answer
Any idea to fix this.
Your installation script has spawned a child process.
Add a ps -f
or ptree $$
command before echo hi
. You’ll see a child process or multiple child processes spawned by your install script.
To stop the SSH command from hanging, you need to detach such child process(es) from your terminal’s input/output. You can sedirect your script’s output to a file – both stdout
and stderr
with > /some/output/file 2>&1
, and also redirect its input with < /dev/null
.
Or you can use the nohup
command.
You haven’t provided an MCVE, as others have noted, but this is likely the problem command in you install script, since your question implies that you see the expected output from your install script:
./tctl start test
You probably would do better to replace it with something like:
./tctl start test </dev/null >/some/log/file/path.log 2>&1