#!/bin/sh # zap, kills processes that match strings on command line, queries for confirm # if no -signal is give as $1 # /kc ken chase mathboy@sizone.org # v0.001 summer 1994 # v0.002 spring 1995 # v0.003 summer 1996 # v0.004 fall 1996 # v0.005 apr 1997 # v.0006 aug 1997 if [ "$1" = "" ] || [ "$0" = "-h" ]; then echo "ZAP -- GPL'd -- by Ken Chase math @ sizone . org" echo "usage: $0 {command} [command2 [command3 .. ]]" echo " will kill procs from ps -axw table matching strings on command line" echo " querying for confirmation of kill" exit fi # check if there's a signal given on cmd line so we can have unattended op. manual=1 if [ "`echo $1 | cut -c1`" = "-" ]; then signal=$1 unset manual shift fi # grab all remaining command args b=$* # turn spaces into |s for egrep, and turn (s and )s into \(s and \)s so we # can even zap '(swapped out)' procs by specifying () on cmd line # and have (s protected from egrep a=`echo $b | sed 's/(/\\\(/g' | sed 's/)/\\\)/g' | tr ' ' '|'` echo Finding "($a)" # real fucking stupid to do this kludge - 'for i' will parse on every # space returned from ps -auxw, cant keep it in integral lines - if we # set IFS to " " then we cant use `command | command` # so instead have to grep for commands, pull procid and regrep for procid # I guess that zapping a grep wont work since we have to reject grepping on # grep or on zap itself # show matching commands in full ps -axw style ps -axw | egrep "($a)" | egrep -v '(grep|zap)' echo for i in `ps -axw | egrep "($a)" | egrep -v "(grep|zap)" | awk '{print $1}'` do #echo $i c=`ps auxw | egrep "^ *[a-z]+ *"$i | egrep -v "(grep|zap)"` if [ "$manual" ]; then if [ "$c" != "" ]; then echo -n zap: $c '? ' read signal manual=1 signal="-"$signal fi fi if [ "$signal" != "n" ] && [ "$signal" != "" ]; then signal=`echo $signal | tr "[a-z]" "[A-Z]"` case $signal in "-y") k='-15';; "-yes") k='-15';; *) k=$signal esac echo "signal given was '$signal'='$k'" if [ "$k" != "-n" ] && [ "$k" != "-no" ]; then echo "Killing $k $i" kill $k $i echo fi fi done