#!/bin/sh
# find out if somebody is already running the iserver
# called by tds3 command script
#  Helmut Heller & Brad Banko 2/13/91
#
OTHERUSER="`ps -ef | grep iserver | grep -v grep | awk '{print $1}'`"
OTERM="`ps -ef | grep iserver | grep -v grep | awk '{print $6}'`"
CDIR="`pwd`"
#
if  test  -n "$OTHERUSER"
then # mail to other user, write to other user, notify banko, acknowledge
  echo "The B014 transputer board is currently being used by user $OTHERUSER." ;
  if test "$OTHERUSER"!="tguest" 
  then
    echo "$LOGNAME was trying to use the B014 transputer board while you were using it." | Mail -s "transputer use (tds)" $OTHERUSER ;
  fi
  echo "(tds) Another user ($LOGNAME) is also trying to use the B014 transputer board." | write $OTHERUSER $OTERM
  echo "$LOGNAME tried, $OTHERUSER using it, CDIR = $CDIR." | Mail -s "transputer use (tds)" banko ;
  echo "The tguest administrator has been notified of the conflict."
  echo "Please try again after a short while."
  exit 1 
fi
