Date: Sat, 15 Mar 1997 19:18:17 -0600 From: Lee Crites <adonai@jump.net> To: Jen and Luke <isis@servtech.com> Cc: freebsd-questions@freebsd.org Subject: Re: awk<ward> Message-ID: <1.5.4.32.19970316011817.006a41e8@jump.net>
next in thread | raw e-mail | index | archive | help
At 17:33 15-03-97 -0500, Jen and Luke wrote:
>Hi,
>We are trying to make a command to kill something based on its name,
>someone posted the instructions awhile back, but this is as far as we
>got...
>ps -ax | grep "string" | grep -v grep
>
>We know we need to pipe to awk to print the pid, but aren't sure of how
>to do it... Oh, and the man page sucks...:) How do we nominate it for
>the worst man page award?
The nomination question will have to be answered by someone else. However,
the kill question I can handle.
Try this puppy on for size. It assumes you have a one word "string" to
identify your intended victim(s).
Lee
----- start of killem script -----
#!/bin/csh -f
# name: killem
#
# This script kills all processes with $1 in the ps line. If a kill
# signal is needed, it is $2
#
#
# check for word to search for
#
if ($1 == "") then
echo "usage: $0 word [signal]"
exit
endif
#
# get list of process ids
#
set pids = `ps -auxwww|grep $1|grep -v grep|grep -v $0|awk '{print $2}'`
#
# tell me about it
#
if ("$pids" == "") then
echo "nothing to kill"
exit
endif
echo "killing "$pids
#
# do the dirty deed
#
kill $2 $pids
#
# done
#
----- end of killem script -----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1.5.4.32.19970316011817.006a41e8>
