Professional Documents
Culture Documents
/bin/sh
# Alexis Megas, 2005.
# Alexis Megas, 02/24/2007. Removed clear call.
# Alexis Megas, 07/04/2007. Direct errors to /dev/null.
# A script that allows the superuser to CONTINUE or STOP another
# user's processes. The script executes in interactive or
# non-interactive modes.
force=0
usage="usage: stop_user_processes.sh -c|-s -u USERID [-f(orce)]"
answer=""
for pid in `ps -U $userid -o pid 2> /dev/null | tail +2 2> /dev/null`
do
name="`ps -U $userid -o pid,comm 2> /dev/null | grep \" $pid \" 2> /dev/null |
awk '{print $2}' 2> /dev/null`"
if [ -z "$name" ]
then
continue
fi
read answer
while [ "$answer" != "a" -a "$answer" != "n" -a "$answer" != "q" \
-a "$answer" != "y" ]
do
if [ "$sig" = "-STOP" ]
then
echo "Stop $pid ($name)? [a/n/q/y]: \c"
else
echo "Continue $pid ($name)? [a/n/q/y]: \c"
fi
read answer
done
if [ "$answer" = "n" ]
then
continue
elif [ "$answer" = "q" ]
then
exit 0
fi
fi
if [ $? -eq 0 ]
then
if [ "$sig" = "-STOP" ]
then
echo "$pid ($name) stopped."
else
echo "$pid ($name) continued."
fi
else
if [ "$sig" = "-STOP" ]
then
echo "Error stopping $pid ($name)."
else
echo "Error continuing $pid ($name)."
fi
fi
done
exit 0