From owner-freebsd-questions Sat Mar 15 17:19:14 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id RAA18115 for questions-outgoing; Sat, 15 Mar 1997 17:19:14 -0800 (PST) Received: from jump.net (serv1-2.jump.net [204.238.120.19]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id RAA18066 for ; Sat, 15 Mar 1997 17:19:01 -0800 (PST) Received: from benjamin.adonai.com by jump.net (8.8.5/BERK-6.8.11) id TAA01562; Sat, 15 Mar 1997 19:18:30 -0600 (CST) Message-Id: <1.5.4.32.19970316011817.006a41e8@jump.net> X-Sender: adonai@jump.net X-Mailer: Windows Eudora Light Version 1.5.4 (32) Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Sat, 15 Mar 1997 19:18:17 -0600 To: Jen and Luke From: Lee Crites Subject: Re: awk Cc: freebsd-questions@freebsd.org Sender: owner-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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 -----