Re: Script to kill processes after grep

From: Dana (dtjaeger@COX.NET)
Date: Mon Dec 02 2002 - 19:36:06 EST


----- Original Message -----
From: "Aaron Morris" <aaronmorris@MINDSPRING.COM>
Newsgroups: bit.listserv.aix-l
To: <aix-l@Princeton.EDU>
Sent: Monday, December 02, 2002 12:43 PM
Subject: Re: Script to kill processes after grep

> Use this as your script:
>
> ps auxw|grep "$1"|grep -v grep|awk {'print $2'}|xargs kill
>
> It's just that simple.
>
> Wesley Joyce wrote:
> > I am attempting to write a script that would kill any processes using
the
> > kill command after the script greps' for the process(es) arguments.
> >
> > For example, I have these process that I would like kill both by running
> > one script that greps for 'adminex:/' for example.
> >
> > root 104368 90326 0 Nov 19 - 0:01 rcp -rp ./banner adminex:/
> > root 75010 73126 0 Nov 28 - 0:08 rcp -rp ./users adminex:/
> >
> > Here is the core of script so far -
> > kill 'ps -efo "%p %a" | grep $1 | cut -c 1-6'
> >
> > # !grepkill.shl adminex
> >
> > !grepkill.shl: ps -efo "%p %a" | grep $1 | cut -c 1-6: Specify a process
> > identifier or a %job number.
> >
> > If I just run the script without the kill part, I get a list of all the
> > PIDS
> >
> > 10000
> > 10001
> > 10002
> >
> > which is good, but it fails on the kill part. I know it has to be
> > something simple. What am I doing wrong? I am sure someone has a more
> > elegant script(s).
> >
> >
> >
> > Wesley Joyce, Systems Administrator
> > Center for Administrative Computing (CAC), IT
> > University of the Virgin Islands
> > #2 John Brewers Bay, St. Thomas, USVI 00802-9990
> > (340) 693-1469 (voice) / (340) 693-1465 (fax)
> > http://www.uvi.edu
> >
> > "If you can't explain it simply, than you don't know it well enough. -
> > Unknown."
> >
>
> --
> Aaron W Morris



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:23 EDT