#!//usr/bin/csh -f
#+
#NAME
# osirisCleanVncDir - removes old .log, .pid, and .info files from ~/.vnc
#
#PURPOSE
#	make sure we're not overwriting .info files which are used to 
#       start the appropriate VNC viewer
#
#
#USAGE
#	osirisCleanVncDir
#	called from osirisStartVncServers
# 
#ARGUMENTS
#	None
# 
#OUTPUT
#	None
# 
#RESTRICTIONS
#	Must be run as osiris numbered account
# 
#EXIT VALUES
#	0 = normal completion
#	1 = wrong number of arguments
#       2 =
#       3 = not run on default computer (napili)
#
#EXAMPLES
#	1) Start the vncviewer in interactive mode:
#		osirisCleanVncDir
#
#-
# Modification history:
#	2006 May 04	jlyke	Original
#
#-----------------------------------------------------------------------

# define initial values...
set buf = $0
set cmd = $buf:t
set usage = "Usage: $cmd"
# alias echo so we can ring the bell
alias echo /usr/bin/echo


# define defaults
set computer = "napili"
set viewonly = ""
set depth = 24
echo ""
set logdir = "~/.vnc"
set user = `whoami`

# make sure we're running on napili
set mycomp = `hostname`
if ( $mycomp != $computer ) then
  echo ""
  echo "\aWarning: $cmd must be run from $computer"
  echo ""
  exit 3
endif

# get running vnc servers that belong to the user
set running = `vnc | awk '/'$user'/ {print $3}'`

# get list of files in logdir
cd $logdir
set list = `ls *.log`

foreach file ($list)
  set good = 0
  set buf = $file
  set base = $buf:r
  foreach server ($running)
    if ( $base == $server ) then
      set good = 1
      break
    endif
  end
  if ( $good != 1 ) then
    foreach ext ( log pid info )
      if ( -e $base"."$ext ) then
        rm $base"."$ext
      endif
    end
  endif
end


exit 0