1

I'm using Porteus 3.2.2 to connect to a VNC server in the internet through a SSH tunnel, and I'm trying to automate it as much as possible.

I have this script that creates the tunnel and keeps it open, but I would like to tweak it a little bit.


#!/bin/bash

#create SSH tunnel
ssh -L 5901:192.168.1.200:5901 -t [email protected] 'vncserver -geometry 1280x800; /bin/bash'

#open vncviewer
vncviewer -fullscreen localhost:5901

exit 0

  • I would like it to minimize the terminal window after logging in to the server.

  • Also AFTER login successfully, I would like it to open vncviewer with no terminal window, and with the options above.

The way I have the script doesn't work because it only launches after the ssh tunnel closes. And I can't use '&' to send the ssh tunnel to background. Also, if I put vncviewer before the SSH tunnel and send it to background I can't use the options...

Any help here?

Thanks in advance

4
  • Why can't you use '&'? Commented Nov 22, 2017 at 13:15
  • Because SSH tunneling doesn't allow it... Only vncviewer, but I just want to launch vncviewer AFTER the SSH tunnel is running...
    – Luis
    Commented Nov 22, 2017 at 13:45
  • ??? Making background any task is bash's job, so any command can be put to background. What does it mean "SSH tunneling doesn't allow it"? Does It say permission denied or what? Commented Nov 22, 2017 at 13:56
  • It just says that it can't be backgrounded... I don't know if it is because it asks a password...
    – Luis
    Commented Nov 22, 2017 at 14:47

1 Answer 1

1

Adding the -f option to your SSH command line should get you closer to what you want: it causes the ssh client to go to the background, but only after the connection has been established and any password requests have been fulfilled, allowing vncviewer to start once the SSH connection has been established.

If starting the VNC server at the remote system takes a noticeable amount of time, you might want to add sleep <some number of seconds> between the ssh command line and the vncviewer command line, to allow the VNC server to complete start-up before vncviewer attempts to connect to it.

Minimizing the terminal window would require sending a "minimize/iconify this window" command to the window manager of your local desktop environment. The details will depend on the type of desktop environment you're using, but in general, the commands wmctrl or xdotool might be able to do it.

Please see: How to hide or minimize X11 window from console?

2
  • Thanks for the reply. I will try the -f flag, it sounds just like what I need...
    – Luis
    Commented Nov 22, 2017 at 14:56
  • Thanks, man. That did the trick! Used the -f flag and after successful ssh login, it sets itself to background leaving the tunnel open, after which it launches vncviewer with all the options i want. As for minimizing the window, i think i won't bother with that for now...
    – Luis
    Commented Nov 23, 2017 at 8:15

You must log in to answer this question.

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