<html>
<body>
<br>
Dear Gurus,<br><br>
A BIG thank you to all for your contributions. I have learnt from ALL
your examples. <br><br>
Here is what I have ended up with:- <br><br>
<font color="#0000FF">ps x | grep &quot;[s]sh -f -N&quot; | awk '{ print
$1 }' | xargs kill -p<br><br>
</font>I suppose this would work great if there were only 1 process as a
result of the cmd above. <br><br>
What would happen if there were more than 1 PID from std output?
<br><br>
Will it kill ALL PIDs that were produced from std output?<br><br>
Thanks again. :)<br><br>
Best Regards,<br>
Andrew<br><br>
<br>
At 11:28 PM 15/06/2005, Purcocks, Graham wrote:<br>
<blockquote type=cite class=cite cite=""><font face="arial" size=2 color="#0000FF">I
use<br>
</font>&nbsp;<br>
<font face="arial" size=2 color="#0000FF">ps -ef | awk '{print $2}' to
get the pid<br>
</font>&nbsp;<br>
<font face="arial" size=2 color="#0000FF">kill -9 `ps -efw | awk '{print
$2}'`<br>
</font>&nbsp;<br>
<font face="arial" size=2 color="#0000FF">would do it.<br>
</font>&nbsp;<br>
<font face="arial" size=2 color="#0000FF">or ps aux | awk '{print $2}' if
you want to use aux.<br>
</font>&nbsp;<br>
<font face="arial" size=2 color="#0000FF">Graham</font><br>
<hr>
<font face="tahoma" size=2><b>From:</b> whitebox-users-bounces@beau.org
[<a href="mailto:whitebox-users-bounces@beau.org" eudora="autourl">mailto:whitebox-users-bounces@beau.org</a>]
<b>On Behalf Of </b>Andrew Vong<br>
<b>Sent:</b> 15 June 2005 15:56<br>
<b>To:</b> whitebox-users@beau.org<br>
<b>Subject:</b> [WBEL-users] Another Shell Scripting Question<br>
</font><br><br>
Dear Gurus,<br><br>
Thanks for all who responded to my previous question. It worked great!
<br><br>
I am now trying to perform a &quot;ps aux | grep &quot;some regular
expression&quot; | cut -f 2 -d ......&quot;<br><br>
I seem to be having 2 problems. <br><br>
1) What delimiter should I define for cut? I've tried &quot; &quot;
(space) but that does not work.<br>
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 &quot;grep <i>regular expression</i>&quot; ?<br><br>
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??<br><br>
$ ps aux | grep &quot;some regular expression&quot; | cut -f 2 -d ......
| xargs kill -9<br><br>
Or something along those lines... <br><br>
Hope someone out there can help me. <br><br>
Thanks again. :)<br><br>
Best Regards,<br>
Andrew<br>
</blockquote><br>
At 11:45 PM 15/06/2005, John Haxby wrote:<br>
<blockquote type=cite class=cite cite="">Andrew Vong wrote:<br><br>
<br>
<blockquote type=cite class=cite cite="">Dear Gurus,<br><br>
Thanks for all who responded to my previous question. It worked
great!<br><br>
I am now trying to perform a &quot;ps aux | grep &quot;some regular
expression&quot; | cut -f 2 -d ......&quot;<br><br>
I seem to be having 2 problems.<br><br>
1) What delimiter should I define for cut? I've tried &quot; &quot;
(space) but that does not work.</blockquote><br>
cut -c might be better, or <font color="#FF0000">&quot;awk '{print $N}'
</font>where &quot;N&quot; is the number of the column you 
want.<br><br>
If you're killing stuff, perhaps &quot;killall&quot; is what you
want.<br><br>
<blockquote type=cite class=cite cite="">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 &quot;grep
/regular expression/&quot; ?</blockquote><font color="#FF0000">ps -ef |
grep &quot;f\\oo&quot;<br><br>
</font>works nicely.<br><br>
_______________________________________________<br>
Whitebox-users mailing list<br>
Whitebox-users@beau.org<br>
<a href="http://beau.org/mailman/listinfo/whitebox-users" eudora="autourl">http://beau.org/mailman/listinfo/whitebox-users</a><br><br>
</blockquote><br>
At 12:41 AM 16/06/2005, Vincent Raffensberger wrote:<br>
<blockquote type=cite class=cite cite=""><font face="arial" size=2 color="#0000FF">'pgrep'
will give you the pid:<br>
</font>&nbsp;<br>
<font face="arial" size=2 color="#0000FF">$ pgrep ntpd<br>
2106<br>
</font>&nbsp;<br>
<font face="arial" size=2 color="#0000FF">'pkill' could kill it for
you.&nbsp; See the manpage.<br>
</font>&nbsp;<br>
<font face="arial" size=2 color="#0000FF">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.<br>
See the manpage for all the different fields you can select.&nbsp; Here's
an example:<br>
</font>&nbsp;<br>
<font face="arial" size=2 color="#0000FF">$ ps -p `pgrep ntpd` -o
pcpu,pmem,start,pid,cmd<br>
%CPU %MEM&nbsp; STARTED&nbsp;&nbsp; PID CMD<br>
&nbsp;0.0&nbsp; 0.2&nbsp;&nbsp; Jun 13&nbsp; 2106 ntpd -N -b -g -u
ntp:ntp -p /var/run/ntpd.pid<br>
</font>&nbsp;<br>
<font face="arial" size=2 color="#0000FF">If you must grep the full ps
output, you can omit the grep process like this:<br>
</font>&nbsp;<br>
<font face="arial" size=2 color="#0000FF">$ ps aux | grep [n]tp<br>
ntp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2106&nbsp; 0.0&nbsp; 0.2&nbsp;
5052 5052 ?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SLs&nbsp;
Jun13&nbsp;&nbsp; 0:01 ntpd -N -b -g -u ntp:ntp<br>
</font><br>
<hr>
<font face="tahoma" size=2><b>From:</b> whitebox-users-bounces@beau.org
[<a href="mailto:whitebox-users-bounces@beau.org" eudora="autourl">mailto:whitebox-users-bounces@beau.org</a>]
<b>On Behalf Of </b>Andrew Vong<br>
<b>Sent:</b> Wednesday, June 15, 2005 9:56 AM<br>
<b>To:</b> whitebox-users@beau.org<br>
<b>Subject:</b> [WBEL-users] Another Shell Scripting Question<br>
</font><br><br>
Dear Gurus,<br><br>
Thanks for all who responded to my previous question. It worked great!
<br><br>
I am now trying to perform a &quot;ps aux | grep &quot;some regular
expression&quot; | cut -f 2 -d ......&quot;<br><br>
I seem to be having 2 problems. <br><br>
1) What delimiter should I define for cut? I've tried &quot; &quot;
(space) but that does not work.<br>
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 &quot;grep <i>regular expression</i>&quot; ?<br><br>
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??<br><br>
$ ps aux | grep &quot;some regular expression&quot; | cut -f 2 -d ......
| xargs kill -9<br><br>
Or something along those lines... <br><br>
Hope someone out there can help me. <br><br>
Thanks again. :)<br><br>
Best Regards,<br>
Andrew<br>
</blockquote></body>
</html>