PDA

View Full Version : script to start,connect,kill vnc


frisco
October 17th, 2003, 22:46
Was asked to do this at work today.

[code:1:3fde99f557]
#!/bin/bash

LD_LIBRARY_PATH=/usr/local/lib
PATH=$PATH:/usr/openwin/bin:/usr/X11R6/bin


mysession=$(vncserver $@ 2>&1 | grep '^New '| sed "s/^.*://")

if [ X${mysession} != 'X' ]; then
vncviewer -passwd $HOME/.vnc/passwd localhost:${mysession}
vncserver -kill :${mysession}
else
echo 'Could not start vncserver!'
fi
[/code:1:3fde99f557]

Place this script on a remote server, let's say in $HOME/bin/myvnc.
Connect to it via: ssh -XC login@hostname bin/myvnc
Assumes you've run vncserver once before (to create the .vnc/passwd file) and that sshd on the remote server does X forwarding.
You can pass vncserver args like this: ssh -XC login@hostname bin/myvnc -geometry 640x480

The first two vars are set b/c the script was being run on some solaris/linux servers with questionable env's.

If you haven't run vncserver before, check out $HOME/.vnc/xstartup. For example, on Solaris we might add '/usr/dt/bin/Xsession' to it so our dba's get the environment they're used to.

This script should have some traps set to capture killing the ssh session while vncserver is still running and still kill off the vncserver but i wanted to go home. Also, if future versions of vncserver change their output this script may stop working.

You can connect from windows if you have cygwin/ssh/X set up and have run startxwin.


There are other ways to do this, the main goal of this was to provide single session, close everything up afterwards, only have to run one command.