Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am doing a double hop SSH to get first into a server which has a public IP address and open SSH port, then SSHing into the next computer, while linking my local VNC port to the remote systems port. IN a diagram:

[My Local System] ---SSH Tunnel (port 5900 forward)--> [Server] -- SSH Tunnel (port 5900 forward)--> [Remote system]

I have created a single string command to do all of this, but there is a catch. x11VNC appears to crash an inordinate amount. Like literally I might get 10 mins of work done before my system freezes again and I have to restart x11vnc. But this is not what this question is about.

The command I am using is as follows:

ssh -L 5900:[REMOTE SYSTEM IP]:5900 user@FQDN.SERVER.NET 'ssh [REMOTE SYSTEM IP] 'pkill x11vnc; x11vnc --ncache 10''

Now I have included the PKILL command in here so it will clear out the frozen x11vnc instance that is still running so I can free up port 5900 (and not have zombie processes permeating my system): However this doesnt work. No matter what I do, if its a double hop, this just returns x11vnc, command not found

NOTE: If I remove pkill, this command string works perfectly. But I need to kill the zombie

If from the server however I try running the command:

ssh [REMOTE SYSTEM IP] 'pkill x11vnc; x11vnc --ncache 10' 

this works fine! Does anyone know why this wont work when doing a "double hop" ssh connection?

share|improve this question

From your example, it looks like you're nesting a set of single quotes within another set of single quotes. You will need to "escape" the inner set of quotes and the semicolon like this:

ssh -L 5900:[REMOTE SYSTEM IP]:5900 user@FQDN.SERVER.NET 'ssh [REMOTE SYSTEM IP] \'pkill x11vnc\; x11vnc --ncache 10\''

Alternatively, you can make a small batch file on the system running x11vnc. The script does the kill then x11vnc for you, then all you do is run the script as your final command.

share|improve this answer
    
True story, I was just hoping that I would be able to find a way around doing that. That just results in a variety of little scripts just kicking around everywhere. I suppose I could rewrite the x11vnc execution script to something like x11vnc-single which first does the pkill of any running instance. Either way, thank you for your help, and insights. – dynamphorous Mar 1 '12 at 20:56
    
I did try escaping the inner quotes, but found it just kicked back unexpected EOF while searching for matching `'' . That was unexpected. – dynamphorous Mar 1 '12 at 20:59
    
You might try using different quotes for the two commands. Use "" for the outer one, then '' for the inner ones. You might need to escape the ";" between pkill and x11vnc. – dan_linder Mar 1 '12 at 21:13
    
You are correct. But there is one further thing, it needs to use the backtick (grave accent) rather than single quote marks for the inner marks. I will post as the answer when I am allowed too (will take me 3 more hours due to my reputation) Thanks again – dynamphorous Mar 1 '12 at 22:32
up vote 0 down vote accepted

I was able to finally solve the problem. It turns out that I needed to use ` instead of ' for the inner ''. (backtick (grave accent) instead of single quote)

So the final, working command is:

ssh -L 5900:[REMOTE SYSTEM IP]:5900 user@FQDN.SERVER.NET 'ssh [REMOTE SYSTEM IP \`pkill x11vnc\; x11vnc --ncache 10\`'
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .