Listing 5: grpkill.sh
#!/bin/sh
#######################################################
#
# grpkill.sh - allow local administrator to kill
# process of users in a group
# specified by the first parameter
#
#######################################################
# VARIABLES
AMPLOG=/usr/bin/amp/amp.log
GROUP=${1}
PARM="-ef"
clear
if [ $# -ne 1 ]
then
echo "\nUsage: grpkill.sh groupid"
sleep 3
exit 1
fi
echo "\nEnter the process IDs to kill below:"
echo "> \c"
read PROCS
echo "$DT:$UNAME: kill -9 $PROCS" >> $AMPLOG
OKPROCS=""
for PID in $PROCS
do
# Check for process IDs < 20
if [ $PID -lt 20 ]
then
NOKILL="$NOKILL $PID"
else
# Get process owner's GID
USERID=`ps $PARM | awk '{if ( $2 == PROC )
{ print $1 } }' PROC=$PID`
USERGID=`grep "^$USERID:" /etc/passwd | awk -F: '{
print $4 }'`
# Check process owner's GID
if [ "$GROUP" = "$USERGID" ]
then
OKPROCS="$OKPROCS $PID"
else
NOKILL="$NOKILL $PID"
fi
fi
done
if [ -n "$NOKILL" ]
then
echo "\nSorry, you are not authorized "
echo "to kill the following process(es): "
echo "$NOKILL"
fi
if [ -n "$OKPROCS" ]
then
echo "\nNow killing $OKPROCS..."
kill -9 $OKPROCS
fi
echo "\nDone...\n"
sleep 2
exit 0
# End of File
|