Re: Script to kill processes after grep

From: Bill Verzal (Bill_Verzal@BCBSIL.COM)
Date: Mon Dec 02 2002 - 10:14:51 EST


...and remember this tip:

     ps -ef | grep [x]xxxx eliminates the need for the second grep when
looking for xxxxx.

BV
--------------------------------------------------------------------------------------------------------

Bill Verzal
Technical Consultant
Forbes Technical Consulting
(312) 653-3684
bill_verzal@bcbsil.com
billverzal@imcingular.com (Pager)
888-428-4025 (Pager)
MailStop: 27.202B

                    "Ford, Phillip"
                    <phillip.ford@S To: aix-l@Princeton.EDU
                    PCORP.COM> cc:
                    Sent by: "IBM Subject: Re: Script to kill processes after grep
                    AIX Discussion
                    List"
                    <aix-l@Princeto
                    n.EDU>

                    12/02/2002
                    09:08 AM
                    Please respond
                    to "IBM AIX
                    Discussion
                    List"

We use a for loop

for pid in `ps -ef | grep xxxxx | grep -v grep | awk '{print $2}'`
do
   kill $pid
done

Hope this helps

--
Phillip Ford
Senior Software Specialist
Corporate Computer Center
Schering-Plough Corp.
(901) 320-4462
(901) 320-4856 FAX
phillip.ford@spcorp.com
-----Original Message-----
From: Wesley Joyce [mailto:Wesley.Joyce@UVI.EDU]
Sent: Monday, December 02, 2002 8:55 AM
To: aix-l@Princeton.EDU
Subject: Script to kill processes after grep
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."
*********************************************************************
This message and any attachments is solely for the intended recipient. If
you are not the intended recipient, disclosure, copying, use or
distribution of the information included in this message is prohibited --
Please immediately and permanently delete.
**********
The information contained in this communication is confidential, private, proprietary, or otherwise privileged and is intended only for the use of the addressee.  Unauthorized use, disclosure, distribution or copying is strictly prohibited and may be unlawful.  If you have received this communication in error, please notify the sender immediately at (312)653-6000 in Illinois; (972)766-6900 in Texas; or (800)835-8699 in New Mexico.
**********


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