开发者

Shell questions

开发者 https://www.devze.com 2023-03-23 20:02 出处:网络
In the following context : VisualVM over ssh I try to execute the 2 following commands in a single script:

In the following context : VisualVM over ssh

I try to execute the 2 following commands in a single script:

ssh -D 9696 john.doe@121.122.123.124
/usr/bin/jvisualvm -J-Dnetbeans.system_socks_proxy=localhost:9696 \
    -J Djava.net.useSystemProxies=true

Having the 2 command like 开发者_开发知识库this does not work because the ssh command starts in an interactive mode, so the VisualVM is started after the ssh is closed (explicitly with an 'exit').

What could be a good way to solve that issue?

PS. I am running MacOS X.


try:

ssh john.doe@121.122.123.124 '/usr/bin/jvisualvm -J-Dnetbeans.system_socks_proxy=localhost:9696 -J Djava.net.useSystemProxies=true'


If I understand your use case properly, you want to setup port-forwarding with the ssh connection then the second command is run on the localhost which uses the forwarded port on the localhost. I think you could try the -f or -n options to ssh to achieve this. It does however require a command to be run on the remotehost. You could use a bogus command like echo &> /dev/null for that.

EDIT:

Something like this seemed to work in a naïve test:

ssh -f -D <port> remotehost <dummy_program_that_doesnt_quit>


This is best done using an SSH key and screen, so that we interact with and can close the SSH session.

I'm also presuming jvisualvm takes control of the terminal so that when it exits, we clean up the screen session. If jvisualvm detaches from the terminal, the script immediately jumps to cleaning up the screen session while jvisualvm is running.

ssh-add .ssh/key
screen -dmS sshproxy ssh -i .ssh/key -D 9696 john.doe@121.122.123.124
/usr/bin/jvisualvm -J-Dnetbeans.system_socks_proxy=localhost:9696 \
-J Djava.net.useSystemProxies=true
screen -r -d sshproxy -X quit
0

精彩评论

暂无评论...
验证码 换一张
取 消