It wasn't me. You can't prove anything.


2008-05-20

Helpful script

VNC is a cool way of controlling computers remotely. Here is a little script for kicking off the vncserver command that gives you a wider screen and kills the vncserver already running.


#!/bin/bash
##################################################################
# Run VNC Server on the local box with some parameters.
##################################################################

# Yes or No routine
YesNo()
{
  echo -e "$1 (y/n)? \c"
  read answer
  case $answer in
      [yY]|[Yy][Ee][Ss]) answer=y;;
      [nN]|[Nn][Oo]) answer=n ;;
  esac
}

# If VNC Server is already running check if the user wants to kill it.
if  [ -n "`ps -elf | grep Xvnc | grep "${HOST}:1"`" ]; then
  YesNo "VNC Server is already running on display 1, Kill?"
  if [ $answer == 'y' ]; then
      vncserver -kill :1
      sleep 5s
      if  [ -n "`ps -elf | grep Xvnc | grep "${HOST}:1"`" ]; then
          echo "VNC Server :1 is still running. You may have to kill manually."
          exit 1
      fi
  else
      echo "Exiting without running VNC Server."
      exit 0
  fi
fi

# Kick off VNC Server
vncserver :1 -geometry 1280x900



No comments: