[WBEL-users] Another Shell Scripting Question
Vincent Raffensberger
Vincent.Raffensberger at dtn.com
Wed Jun 15 11:41:37 CDT 2005
'pgrep' will give you the pid:
$ pgrep ntpd
2106
'pkill' could kill it for you. See the manpage.
If you want specific ps info for a process, you could ask for it along
with the fields you want instead of using cut or awk.
See the manpage for all the different fields you can select. Here's an
example:
$ ps -p `pgrep ntpd` -o pcpu,pmem,start,pid,cmd
%CPU %MEM STARTED PID CMD
0.0 0.2 Jun 13 2106 ntpd -N -b -g -u ntp:ntp -p /var/run/ntpd.pid
If you must grep the full ps output, you can omit the grep process like
this:
$ ps aux | grep [n]tp
ntp 2106 0.0 0.2 5052 5052 ? SLs Jun13 0:01 ntpd -N
-b -g -u ntp:ntp
________________________________
From: whitebox-users-bounces at beau.org
[mailto:whitebox-users-bounces at beau.org] On Behalf Of Andrew Vong
Sent: Wednesday, June 15, 2005 9:56 AM
To: whitebox-users at beau.org
Subject: [WBEL-users] Another Shell Scripting Question
Dear Gurus,
Thanks for all who responded to my previous question. It worked great!
I am now trying to perform a "ps aux | grep "some regular expression" |
cut -f 2 -d ......"
I seem to be having 2 problems.
1) What delimiter should I define for cut? I've tried " " (space) but
that does not work.
2) I usually get 2 processes listed. The actualy one I'm looking for and
the line I just executed. How can I exclude the 2nd process which also
contains the same "grep regular expression" ?
The above is part of a longer one-liner command I'm trying to construct.
I basically want to kill a specific process and I just want to obtain
the PID for it. So, it may end up looking like this??
$ ps aux | grep "some regular expression" | cut -f 2 -d ...... | xargs
kill -9
Or something along those lines...
Hope someone out there can help me.
Thanks again. :)
Best Regards,
Andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://beau.org/pipermail/whitebox-users/attachments/20050615/ac09ba9a/attachment.htm
More information about the Whitebox-users
mailing list