Linux – ubuntu run a command when vnc session starts

linuxvnc

I have ubuntu, vnc server (Xvnc4) starts on boot with 2 sessions:

VNCSERVERS="1:user1 2:user2"
VNCSERVERARGS[1]="-geometry 1024x768 -depth 24"
VNCSERVERARGS[2]="-geometry 1024x768 -depth 24

Every time vnc server starts – I need to login via vnc to each session and start a program manually.

Is it possible to run automatically a command within specific vnc session?

Best Answer

There are a few different ways to get this done as you might imagine, but this is probably the most appropriate. There's a shell script named xstartup created when you run vncpasswd the first time for a user. This file can be modified to run arbitrary code. When modifying and testing changes, set up debug logging and tail the relevant logfiles to troubleshoot the changes.

Several VNC-related files are found in the directory $HOME/.vnc. Among them:

   $HOME/.vnc/xstartup
          A shell script specifying X applications to be run  when  a  VNC
          desktop  is started.  If it doesn’t exist, vncserver will create
          a new one which runs a couple of basic applications.

Often, setup will place logic in ~/.vnc/xstartup and you'll need to use discretion to insert the line to be run when a session is initiated. Try starting something simple but good at producing error messages at first, like

xterm -geometry 40x24+10+10 -ls -title "$VNCDESKTOP Desktop"

For best results insert that line before or after the line in xstartup which starts your window manager.

Related Topic