Reputation: 10139
I am able to run remote script in two ways. First (indirect) #ssh Second (after ssh connection) #ssh # #exit (back to host terminal)
I believe that there is some difference in type of channel forwarding. In other words when I used fist way fo running remote script, output of script should be printed not host mashine but remote one like that of the second way.
I have two machines uturksat1 and uturksat2 In uturksat2, I have a linux script (/tmp/runScript.sh) and Java class Provider. Linux script runs the Provider java application which is open a socket then listening 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
On uturksat1 machine, I have type following command
root@UTURKSAT1:/tmp# ssh uturksat2 /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
It does not return command prompt automatically, I have to press ctrl+c to return
When I have type the following command:
root@UTURKSAT1:/tmp# ssh -t uturksat2 /tmp/runScript.sh
Provider
Waiting for connection
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
Connection to uturksat2 closed.
root@UTURKSAT1:/tmp#
Provider app is not run, I can test it through telnet to port 2004 which Provider is listening.
telnet uturksat2 2004
Finally last problem is that Provider uses log4j to keep its internall log, in the first way of remote linux script execution, log4j lof file is not created, but in the second way it is created.
Upvotes: 0
Views: 694
Reputation: 10139
I have openned same question with different explanation. It has been solved. Thanks your advices which keep my motivation high. Here is the solution as you have already known. Run remote java server in linux script
Upvotes: 0
Reputation: 64563
The only difference between these two commands:
ssh second
script
exit
and
ssh second script
is that in the second case, the script will be started without terminal. To force terminal in the second case you must specify -t
:
ssh -t second script
Update.1
If you want to start the script
in the background and leave ssh
session:
ssh second 'nohup script < /dev/null > nohup.out 2>&1 &'
Upvotes: 2