#!/bin/sh signal="-KILL"; noreply=""; #PATH="/usr/ucb:$PATH"; export PATH prog=`basename "$0"` if echo "$prog" | grep 'i$' > /dev/null; then signal="-INT"; elif echo "$prog" | grep 't$' > /dev/null; then signal="-TERM"; fi uname=`uname`; case $uname in "SunOS") PS_CMD="ps -eaf | sed -e 's,^ *[^ ][^ ]*,,'" ;; "Linux") PS_CMD="ps wax" ;; *) PS_CMD="ps wax" ;; esac help() { cat <"; -s # set signal number (default: $signal) -# same as -s # -SIG e.g. -HUP, -TERM, ... -nr No reply: "y" is assumed. -w # wait # seconds between each process (-nr mode only). -- means end of switches. Notes: Unless -nr is supplied, you are prompted with [y]/n whether to kill each matching process. If stdin is redirected from, say, /dev/null, all prompt responses will be "y" (i.e. the default) The ps(1) command is: $PS_CMD | egrep ... END } while [ "X$1" != "X" ] do case $1 in "-help"|"-h") help; exit 2 ;; "-s") shift; signal="-$1" ;; "-w") shift; wait="$1" ;; "-nr") noreply="1" ;; "--") shift; break ;; "-"*) signal="$1" ;; *) break ;; esac shift done #echo "signal: $signal" if [ "X$1" = "X" ]; then echo echo "No regex supplied!!!" echo help; exit 3 fi psr=`eval $PS_CMD | egrep "$@" | grep -v grep | grep -v slay | sed -e 's,[ ]*$,,'`; if [ "$psr" != "" ]; then echo "$psr" echo "" fi didkill=0 for process in `echo "$psr" | awk '{print $1}' ` do printf "$process kill $signal? [y]/n "; if [ "$noreply" != "" ]; then if [ "$wait" != "" ]; then sleep $wait; fi reply="y"; echo; else read reply; fi if [ "$reply" != "n" ]; then if echo "$signal" | grep "," > /dev/null; then for s in `echo "$signal" | sed -e 's/-//' -e 's/,/ /g'` do echo kill -$s $process; kill -$s $process; sleep 1 done else echo kill $signal $process; kill $signal $process; fi didkill=1 fi done if [ $didkill = "1" ]; then exit 0; else exit 1 fi