VNC Server Init Script

#!/bin/bash
#VNCSERVER INIT SCRIPT

VNC_SERVER=$(which vncserver)

VNC_USER=$(whoami)
export VNC_USER

if [ $VNC_USER == root ]; then
HOME=/$(whoami)
export HOME
else
HOME=/home/$(whoami)
export HOME
fi

VNC_ID=1

case “$1” in
start)
echo -n “Starting Vnc-Server with Terminal-ID $VNC_ID ”

# Delete old PIDs
rm -f $HOME/.vnc/$HOSTNAME:$VNC_ID.pid

if [ -e $HOME/.vnc/$HOSTNAME:$VNC_ID.log ]; then
cat $HOME/.vnc/$HOSTNAME:$VNC_ID.log >> /var/log/vncserver.log 2>&1
rm -f $HOME/.vnc/$HOSTNAME:$VNC_ID.log
fi

sudo -u $VNC_USER -H $VNC_SERVER :$VNC_ID 2>&1
;;
#
stop)
echo -n “Shutting down Vnc-Server ”
$VNC_SERVER -kill :$VNC_ID 2>&1

cat $HOME/.vnc/$HOSTNAME:$VNC_ID.log >> /var/log/vncserver.log 2>&1
rm -f $HOME/.vnc/$HOSTNAME:$VNC_ID.log

;;
#
restart)
$0 stop
$0 start
;;
#
*)
echo “Usage: $0 {start|stop|restart}”
exit 1
;;
esac