rasbeer
Posts: 242
Joined: Wed Mar 07, 2012 8:35 am

Code to SSH in & start VNC in one line?

Mon Feb 17, 2014 9:02 am

I'd like to use my Pi mostly via SSH - so no need to have a VNC server running all the time - but also be able to login via VNC with minimal hassle.

So I thought I'd try to write a compound SSH/VNC command to automate the process, for storage in an alias, eg:

Code: Select all

ssh pi@10.0.0.137 -t 'vncserver -geometry 960x640 -depth 16 :1' && sleep 6 && vncviewer 10.0.0.137:1
This should SSH in, start up the VNC server, wait until it's going, and finally start the viewer. However, I get a grey screen with an X-shaped cursor. (Image & session log below.) Based on a little digging around I think this indicates the X server is running without a windows manager. Does that sound right? How can I start (or keep) the windows manager running? (& given that the Pi's video memory allocation is set at boot, does this approach even offer any real advantages?)

Grey screen:
Image

Session:

Code: Select all

$ ssh pi@10.0.0.137
pi@10.0.0.137's password: 
Linux raspberrypi 3.10.25+ #622 PREEMPT Fri Jan 3 18:41:00 GMT 2014 armv6l
...

pi@raspberrypi ~ $ cat /home/pi/.vnc/raspberrypi:1.log
16/02/14 20:58:29 Xvnc version TightVNC-1.3.9
16/02/14 20:58:29 Copyright (C) 2000-2007 TightVNC Group
16/02/14 20:58:29 Copyright (C) 1999 AT&T Laboratories Cambridge
16/02/14 20:58:29 All Rights Reserved.
16/02/14 20:58:29 See http://www.tightvnc.com/ for information on TightVNC
16/02/14 20:58:29 Desktop name 'X' (raspberrypi:1)
16/02/14 20:58:29 Protocol versions supported: 3.3, 3.7, 3.8, 3.7t, 3.8t
16/02/14 20:58:29 Listening for VNC connections on TCP port 5901
Font directory '/usr/share/fonts/X11/75dpi/' not found - ignoring
Font directory '/usr/share/fonts/X11/100dpi/' not found - ignoring
16/02/14 20:58:30 Xvnc version TightVNC-1.3.9
16/02/14 20:58:30 Copyright (C) 2000-2007 TightVNC Group
16/02/14 20:58:30 Copyright (C) 1999 AT&T Laboratories Cambridge
16/02/14 20:58:30 All Rights Reserved.
16/02/14 20:58:30 See http://www.tightvnc.com/ for information on TightVNC
16/02/14 20:58:30 Desktop name 'X' (raspberrypi:1)
16/02/14 20:58:30 Protocol versions supported: 3.3, 3.7, 3.8, 3.7t, 3.8t
Font directory '/usr/share/fonts/X11/75dpi/' not found - ignoring
Font directory '/usr/share/fonts/X11/100dpi/' not found - ignoring

16/02/14 20:58:36 Got connection from client 10.0.0.2
16/02/14 20:58:36 Using protocol version 3.8
16/02/14 20:58:36 Enabling TightVNC protocol extensions
16/02/14 20:58:44 Full-control authentication passed by 10.0.0.2
16/02/14 20:58:44 Pixel format for client 10.0.0.2:
16/02/14 20:58:44   32 bpp, depth 24, little endian
16/02/14 20:58:44   true colour: max r 255 g 255 b 255, shift r 16 g 8 b 0
16/02/14 20:58:44 Using tight encoding for client 10.0.0.2
16/02/14 20:58:44 Using compression level 1 for client 10.0.0.2
16/02/14 20:58:44 Using image quality level 6 for client 10.0.0.2
16/02/14 20:58:44 Enabling X-style cursor updates for client 10.0.0.2
16/02/14 20:58:44 Enabling cursor position updates for client 10.0.0.2
16/02/14 20:58:44 Enabling LastRect protocol extension for client 10.0.0.2
16/02/14 20:59:04 Client 10.0.0.2 gone
16/02/14 20:59:04 Statistics:
16/02/14 20:59:04   key events received 1, pointer events 325
16/02/14 20:59:04   framebuffer updates 1, rectangles 323, bytes 17824
16/02/14 20:59:04     LastRect markers 1, bytes 12
16/02/14 20:59:04     cursor shape updates 1, bytes 82
16/02/14 20:59:04     cursor position updates 1, bytes 12
16/02/14 20:59:04     tight rectangles 320, bytes 17718
16/02/14 20:59:04   raw bytes equivalent 2457612, compression ratio 138.707078

16/02/14 20:59:57 Got connection from client 10.0.0.2
16/02/14 20:59:57 Using protocol version 3.8
16/02/14 20:59:57 Enabling TightVNC protocol extensions
16/02/14 21:00:05 Full-control authentication passed by 10.0.0.2
16/02/14 21:00:05 Pixel format for client 10.0.0.2:
16/02/14 21:00:05   32 bpp, depth 24, little endian
16/02/14 21:00:05   true colour: max r 255 g 255 b 255, shift r 16 g 8 b 0
16/02/14 21:00:05 Using tight encoding for client 10.0.0.2
16/02/14 21:00:05 Using compression level 1 for client 10.0.0.2
16/02/14 21:00:05 Using image quality level 6 for client 10.0.0.2
16/02/14 21:00:05 Enabling X-style cursor updates for client 10.0.0.2
16/02/14 21:00:05 Enabling cursor position updates for client 10.0.0.2
16/02/14 21:00:05 Enabling LastRect protocol extension for client 10.0.0.2
16/02/14 21:00:08 Client 10.0.0.2 gone
16/02/14 21:00:08 Statistics:
16/02/14 21:00:08   framebuffer updates 1, rectangles 323, bytes 17824
16/02/14 21:00:08     LastRect markers 1, bytes 12
16/02/14 21:00:08     cursor shape updates 1, bytes 82
16/02/14 21:00:08     cursor position updates 1, bytes 12
16/02/14 21:00:08     tight rectangles 320, bytes 17718
16/02/14 21:00:08   raw bytes equivalent 2457612, compression ratio 138.707078
pi@raspberrypi ~ $

User avatar
topguy
Posts: 5965
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Code to SSH in & start VNC in one line?

Mon Feb 17, 2014 9:30 am

If the Pi is configured to automatically start X and log-in on the terminal, you can use x11vnc (instead of vncserver) to connect to the existing X-session.

vncserver creates a new X-session, different from the one running on the display, so what you see seems exactly like a X-session without window-manager.

rasbeer
Posts: 242
Joined: Wed Mar 07, 2012 8:35 am

Re: Code to SSH in & start VNC in one line?

Mon Feb 17, 2014 1:29 pm

Thanks - maybe I'll do that then...

Does anyone know it there's a way to what I was originally planning (ie automate the VNC login process without having a pre-existing X-session running)? And with the fixed video memory allocation, is this even worthwhile? (It's a 256MB Pi...)

User avatar
default_user8
Posts: 678
Joined: Mon Nov 18, 2013 3:11 am

Re: Code to SSH in & start VNC in one line?

Mon Feb 17, 2014 6:16 pm

Your PI is more than capable of running a vncserver all the time. I'm Samba, VNC, minidlna, and raspicheck on mine 24/7 and it rarely if ever sees more than a 5% load on the cpu. If you start a vnc session every time you log in you'll have to kill that session when you log out or you'll have session after session after session running all the time. Starting a vncserver when you ssh in doesn't stop when you log out like some other processes.
Two heads are better than one, unless one's a goat head.

Return to “Beginners”