1

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.

Community
  • 1
  • 1
Nikko
  • 21
  • 1

3 Answers3

1

try:

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

ennuikiller
  • 46,381
  • 14
  • 112
  • 137
  • Doesn't that try to execute jvisualvm on the target host of the ssh ? (Which is not my intent) – Nikko Jul 27 '11 at 15:03
0

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>

suvayu
  • 4,271
  • 2
  • 29
  • 35
  • According to the documentation the -n option cannot be used when a password is required (which is my case) – Nikko Jul 27 '11 at 17:05
  • Hence I said `-f` or `-n`. ;) Also you can try setting up ssh keys as an alternative. – suvayu Jul 27 '11 at 17:11
0

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
brightlancer
  • 2,059
  • 15
  • 7