#!/bin/bash

# 86 -  (version  3 Apr 10)
# kill any command containing $1 


USERID=`whoami`

if [ "$USERID" == "root" ]
then
      echo '86: >>> WARNING - this command may not be run as root'
else

   # RM_CMD - command to be used for removing files and directories
   if [ -e /usr/bin/rm ]
	   then
      RM_CMD=/usr/bin/rm
   else
      if [ -e /bin/rm ]
   	   then
	 RM_CMD=/bin/rm
      else
	 RM_CMD=rm
      fi
   fi

   # Creat a list of jobid's matching $1
   ps -u $USERID | grep $1 | cut -c1-6 | tr -d " " > /tmp/86_$$

   # kill any job matching $1 except this script
   for JOBID in `cat /tmp/86_$$`
   do
       if [ $JOBID != $$ ]
       then 
          kill -9 $JOBID
       fi
   done

   $RM_CMD /tmp/86_$$
fi
