#!/bin/bash #+ # NAME: # vnc # PURPOSE: # Control use of vncserver. # CALLING SEQUENCE: # vnc # vnc list # vnc start # vnc kill # vnc kill=session # INPUTS: # session vnc session number # PROCEDURE: # > No argument displays syntax information # > Arg 'list' displays all sessions stored in the file ~/.vnc/vnc.log # > If argument 'start' is specified then the program vncserver is called to # start a new vnc session. The session number is stored in the file # ~/.vnc/vnc.log # > If argument 'kill' is specified (without a session number) then an # attempt is made to kill every vnc session listed in the file # ~/.vnc/vnc.log. When a session is killed successfully the matching # entry in ~/.vnc/vnc.log is removed. # > If 'kill=session' is specified as argument the vnc session # with the specified number is killed, and removed from ~/.vnc/vnc.log # > When a session is killed several files are automatically deleted # (# is a one-digit integer) # - a *.pid file: ~/.vnc/cass180.ucsd.edu:#.pid # - a link to an X-server: /tmp/.X11-unix/X# # - a lock file /tmp/X#-lock # > Not automatically deleted is a log file: # - ~/.vnc/cass180.ucsd.edu:#.log # This file can get quite big (Gigabytes) and is explicitly deleted # by this script. # MODIFICATION HISTORY: # JAN-2001, Paul Hick (UCSD/CASS; pphick@ucsd.edu) #- if [ "$(which vncserver 2> /dev/null)" == "" ]; then echo "vnc: vncserver not found; not installed or not in path" exit 1 fi vncdir=~/.vnc vnclog=$vncdir/vnc.log vnctmp=$vncdir/vnc.tmp touch $vnclog if [ -z "$1" ]; then echo "syntax 1: vnc start (starts a new vnc session)" echo "syntax 2: vnc start=i (starts a new vnc session on specified display)" echo "syntax 3: vnc list (lists all vnc sessions)" echo "syntax 4: vnc kill (kills all vnc sessions)" echo "syntax 5: vnc kill=i (i=integer; kills the specified vnc sessions)" elif [ "$1" == "list" ]; then cat $vnclog | while read line; do echo $line done echo "------------------------------" elif [ "$(echo $1 | gawk -F= '{print $1}')" == "start" ]; then vncserver :"$(echo $1 | gawk -F= '{print $2}')" 2> $vnctmp session=$(cat $vnctmp | grep "desktop is $HOSTNAME") if [ $? == 0 ]; then echo $session session=$(echo "$session" | gawk -F" desktop is " '{print $2}') echo $session >> $vnclog fi else mv $vnclog $vnctmp touch $vnclog cat $vnctmp | while read line; do on_host=$line session=$(echo $line | gawk -F: '{print $2}') if [ "$1" == "kill=$session" -o "$1" == "kill" ]; then kill_session=1 else kill_session=0 fi if [ $kill_session == 1 ]; then vncserver -kill :$session echo Killed vnc session $on_host rm -vf $vncdir/$on_host.log else echo $line >> $vnclog fi done fi if [ -f $vnctmp ]; then rm -vf $vnctmp fi exit 0