[WBEL-users] Another Shell Scripting Question
Purcocks, Graham
grahamp at wsieurope.com
Wed Jun 15 14:30:50 CDT 2005
The answer is 'yes'. It will kill all processes which match your grep.
ie kill n1 n2 n3 n4
will kill all 4 processes
________________________________
From: Andrew Vong [mailto:andrewvong at finpress.com]
Sent: 15 June 2005 19:18
To: Will McDonald; Purcocks, Graham; whitebox-users at beau.org; John
Haxby; Vincent Raffensberger
Subject: RE: [WBEL-users] Another Shell Scripting Question
Dear Gurus,
A BIG thank you to all for your contributions. I have learnt from ALL
your examples.
Here is what I have ended up with:-
ps x | grep "[s]sh -f -N" | awk '{ print $1 }' | xargs kill -p
I suppose this would work great if there were only 1 process as a result
of the cmd above.
What would happen if there were more than 1 PID from std output?
Will it kill ALL PIDs that were produced from std output?
Thanks again. :)
Best Regards,
Andrew
At 11:28 PM 15/06/2005, Purcocks, Graham wrote:
I use
ps -ef | awk '{print $2}' to get the pid
kill -9 `ps -efw | awk '{print $2}'`
would do it.
or ps aux | awk '{print $2}' if you want to use aux.
Graham
________________________________
From: whitebox-users-bounces at beau.org
[mailto:whitebox-users-bounces at beau.org] On Behalf Of Andrew Vong
Sent: 15 June 2005 15:56
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
At 11:45 PM 15/06/2005, John Haxby wrote:
Andrew Vong wrote:
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.
cut -c might be better, or "awk '{print $N}' where "N" is the
number of the column you want.
If you're killing stuff, perhaps "killall" is what you want.
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/" ?
ps -ef | grep "f\\oo"
works nicely.
_______________________________________________
Whitebox-users mailing list
Whitebox-users at beau.org
http://beau.org/mailman/listinfo/whitebox-users
At 12:41 AM 16/06/2005, Vincent Raffensberger wrote:
'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/d87615ca/attachment-0001.htm
More information about the Whitebox-users
mailing list