Unix administration - grep format assistance required

This is Interesting: Free IT Magazines  
Home > Archive > Unix administration > May 2007 > grep format assistance required





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author grep format assistance required
Tribeguy 15

2007-05-12, 7:17 pm

Hi,
I'm trying to find a way to obtain the PID of qmail-send running on a
FreeBSD 4.7 server using the ps and grep functions.

#ps -aux | grep qmail-send
Results in: (some info removed to fit on single line)
root 85 0.0 0.2 872 300 con- I 1:00.62 supervise qmail-send
qmails 6734 0.0 0.3 972 508 ?? S 1:02.04 qmail-send

How do I modify the above command line to have the output be 6734
only? Note: I only want the PID of the "qmail-send" process (running
as qmails) and not the "supervise qmail-send" (running as root).

TIA,
Shane


Bit Twister

2007-05-12, 7:17 pm

On Sat, 12 May 2007 16:00:22 -0400, Tribeguy 15 wrote:
> Hi,
> I'm trying to find a way to obtain the PID of qmail-send running on a
> FreeBSD 4.7 server using the ps and grep functions.
>
> #ps -aux | grep qmail-send
> Results in: (some info removed to fit on single line)
> root 85 0.0 0.2 872 300 con- I 1:00.62 supervise qmail-send
> qmails 6734 0.0 0.3 972 508 ?? S 1:02.04 qmail-send
>
> How do I modify the above command line to have the output be 6734
> only? Note: I only want the PID of the "qmail-send" process (running
> as qmails) and not the "supervise qmail-send" (running as root).


use pgrep.

_line=$(ps -aux | grep qmail-send | grep -v root)
set -- $_line
_pid=$2
echo $_pid

Tribeguy 15

2007-05-12, 7:17 pm

FreeBSD 4.7 doesn't have pgrep as that would have been too easy.
Thanks for your script which works but is there a way to have it all
in one line. I need to use it in another script which currently is
using:
my ($pidcmd) = 'pidof qmail-send';

TIA,
Shane


On 12 May 2007 20:25:58 GMT, Bit Twister <BitTwister@mouse-potato.com>
wrote:

>On Sat, 12 May 2007 16:00:22 -0400, Tribeguy 15 wrote:
>
>use pgrep.
>
>_line=$(ps -aux | grep qmail-send | grep -v root)
>set -- $_line
>_pid=$2
>echo $_pid


Chris F.A. Johnson

2007-05-12, 7:17 pm

On 2007-05-12, Tribeguy 15 wrote:
> On 12 May 2007 20:25:58 GMT, Bit Twister <BitTwister@mouse-potato.com>
> wrote:
>

[please don't top post]
[vbcol=seagreen]
> FreeBSD 4.7 doesn't have pgrep as that would have been too easy.
> Thanks for your script which works but is there a way to have it all
> in one line.


Why do you need it all on one line? All that does is make it harder
to read and to update.

> I need to use it in another script which currently is
> using:
> my ($pidcmd) = 'pidof qmail-send';


That's not a shell script.

--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
Michael Heiming

2007-05-13, 7:24 pm

In comp.unix.admin Tribeguy 15 <tribeguy_15@hotmail.com>:
> Hi,
> I'm trying to find a way to obtain the PID of qmail-send running on a
> FreeBSD 4.7 server using the ps and grep functions.


> #ps -aux | grep qmail-send
> Results in: (some info removed to fit on single line)
> root 85 0.0 0.2 872 300 con- I 1:00.62 supervise qmail-send
> qmails 6734 0.0 0.3 972 508 ?? S 1:02.04 qmail-send


> How do I modify the above command line to have the output be 6734
> only? Note: I only want the PID of the "qmail-send" process (running
> as qmails) and not the "supervise qmail-send" (running as root).


ps -aux | awk '/[q]mail-send/&&$1="qmails"{print $2}'

Use what does the job.

Good luck

--
Michael Heiming (X-PGP-Sig > GPG-Key ID: EDD27B94)
mail: echo zvpunry@urvzvat.qr | PERL -pe 'y/a-z/n-za-m/'
#bofh excuse 332: suboptimal routing experience
Jean-Rene David

2007-05-14, 1:20 pm

* Tribeguy 15 [2007.05.12 20:00]:
> #ps -aux | grep qmail-send
> Results in: (some info removed to fit on single line)
> root 85 0.0 0.2 872 300 con- I 1:00.62 supervise qmail-send
> qmails 6734 0.0 0.3 972 508 ?? S 1:02.04 qmail-send
>
> How do I modify the above command line to have the output be 6734
> only? Note: I only want the PID of the "qmail-send" process (running
> as qmails) and not the "supervise qmail-send" (running as root).


If qmails doesn't run any other process, this might do:

ps -u qmails -o pid=

Otherwise:

ps -u qmails -o pid= -o comm= | awk '$2 ~ /qmail-send/ {print $1}'


--
JR
Brian Beuchaw

2007-05-14, 7:18 pm

Tribeguy 15 <tribeguy_15@hotmail.com> wrote:
> Hi,
> I'm trying to find a way to obtain the PID of qmail-send running on a
> FreeBSD 4.7 server using the ps and grep functions.
>
> #ps -aux | grep qmail-send
> Results in: (some info removed to fit on single line)
> root 85 0.0 0.2 872 300 con- I 1:00.62 supervise qmail-send
> qmails 6734 0.0 0.3 972 508 ?? S 1:02.04 qmail-send
>
> How do I modify the above command line to have the output be 6734
> only? Note: I only want the PID of the "qmail-send" process (running
> as qmails) and not the "supervise qmail-send" (running as root).


This should work:

ps -aux | grep qmail-send | grep -v supervise
or
ps -aux | grep qmail-send | grep -v root

brian
--
If you want to reply to this message by mail, you will
have to change the reply address to beuchaw@beuchaw.net
Tribeguy 15

2007-05-14, 7:18 pm

On Sun, 13 May 2007 20:39:07 +0200, Michael Heiming
<michael+USENET@www.heiming.de> wrote:

>In comp.unix.admin Tribeguy 15 <tribeguy_15@hotmail.com>:
>
>
>
>ps -aux | awk '/[q]mail-send/&&$1="qmails"{print $2}'
>
>Use what does the job.
>
>Good luck


Of all the replies this one is the closest to what I'm looking for.
The output of your script results in:

server# ps -aux | awk '/[q]mail-send/&&$1="qmails"{print $2}'
85
6734

I need just the "6734" being returned as that is the PID of the actual
qmail-send process. If you can update your script to do this that
would be appreciated.

TIA,
Shane
Dave Hinz

2007-05-14, 7:18 pm

On Mon, 14 May 2007 16:32:34 -0400, Tribeguy 15 <tribeguy_15@hotmail.com> wrote:
> On Sun, 13 May 2007 20:39:07 +0200, Michael Heiming
><michael+USENET@www.heiming.de> wrote:
>
>
> The output of your script results in:
> server# ps -aux | awk '/[q]mail-send/&&$1="qmails"{print $2}'
> 85
> 6734
>
> I need just the "6734" being returned as that is the PID of the actual
> qmail-send process. If you can update your script to do this that
> would be appreciated.


Wow. Apparently you have misunderstood the purpose of this group. It's
not "free consulting for people who want us to do their work for them".
He gave you everything you need, and answering your question doesn't
mean he owes you anything more; your response seems to indicate it does.

Tribeguy 15

2007-05-15, 1:21 pm

On 14 May 2007 22:57:53 GMT, Dave Hinz <DaveHinz@gmail.com> wrote:

>On Mon, 14 May 2007 16:32:34 -0400, Tribeguy 15 <tribeguy_15@hotmail.com> wrote:
>
>Wow. Apparently you have misunderstood the purpose of this group. It's
>not "free consulting for people who want us to do their work for them".
>He gave you everything you need, and answering your question doesn't
>mean he owes you anything more; your response seems to indicate it does.


Yes, I guess I did misunderstand. I tought newsgroups could be used
for asking for assistance from people who know more about a subject
then themselves. Then the more knowledgable people could feel good
about helping someone out. I know I would return such assistance if I
could and feel great about helping someone.
You're correct about Dave not owing me anything but if he's like me he
wouldn't mind spending another 20s to answer my question exactly as I
had previously stated.
I tought I had done well in posting my question stating exactly what I
was needing and when I didn't get a suitable answer I didn't know I
couldn't ask for additional assistance.

Shane
Doug Freyburger

2007-05-15, 1:21 pm

Tribeguy 15 <tribeguy...@hotmail.com> wrote:
>
> ... I tought newsgroups could be used
> for asking for assistance from people who know more about a subject
> then themselves. Then the more knowledgable people could feel good
> about helping someone out. I know I would return such assistance if I
> could and feel great about helping someone.


That's correct. Consider - Give a man a fish and feed him for a day.
Teach a man to fish and feed him for life. Thus a partial answer that
gives a pattern that can be built upon is actually a superior answer
than just typing in a script.

> I tought I had done well in posting my question stating exactly what I
> was needing and when I didn't get a suitable answer I didn't know I
> couldn't ask for additional assistance.


One thing I've learned when teaching UNIX - The folks who write down
exactly what I'm typing come ask again when they least variation is
needed and as such they aren't learning any concepts. The folks
who write down skeleton forms based on what I've typing come back
to show off variations and as such have been learning concepts.

So look at the material. Think about why it works. Build a variation
based on the concepts demonstrated. Post what you ended up using.
Trigger professional pride in self and in teacher by both. And in the
process become a contributor. Take and give bundled together.

Michael Heiming

2007-05-16, 1:19 pm

In comp.unix.admin Tribeguy 15 <tribeguy_15@hotmail.com>:
> On Sun, 13 May 2007 20:39:07 +0200, Michael Heiming
> <michael+USENET@www.heiming.de> wrote:


[vbcol=seagreen]
[vbcol=seagreen]
[vbcol=seagreen]
[vbcol=seagreen]
[vbcol=seagreen]
[vbcol=seagreen]
> Of all the replies this one is the closest to what I'm looking for.
> The output of your script results in:


> server# ps -aux | awk '/[q]mail-send/&&$1="qmails"{print $2}'
> 85
> 6734


> I need just the "6734" being returned as that is the PID of the actual
> qmail-send process. If you can update your script to do this that
> would be appreciated.


Thought you had figured out the problem, which should be obvious
if you print $0 instead of $2.

ps -aux | awk '/[q]mail-send/&&$1="qmails"{print $2}'

Should be:

ps -aux | awk '/[q]mail-send/&&$1=="qmails"{print $2}'
^^

--
Michael Heiming (X-PGP-Sig > GPG-Key ID: EDD27B94)
mail: echo zvpunry@urvzvat.qr | PERL -pe 'y/a-z/n-za-m/'
#bofh excuse 194: We only support a 1200 bps connection.
Michael Tosch

2007-05-21, 1:19 pm

Michael Heiming wrote:
> In comp.unix.admin Tribeguy 15 <tribeguy_15@hotmail.com>:
>
>
>
>
>
>
>
>
>
>
> Thought you had figured out the problem, which should be obvious
> if you print $0 instead of $2.
>
> ps -aux | awk '/[q]mail-send/&&$1="qmails"{print $2}'
>
> Should be:
>
> ps -aux | awk '/[q]mail-send/&&$1=="qmails"{print $2}'
> ^^
>


Please omit the "-" in BSD options (and have "-" in SysV options);
I have seen a Linux ps that otherwise sais "depreciated".

aux is BSD:

ps aux | awk '$NF=="qmails-send" {print $2}'

Some systems have pgrep:

pgrep -x qmail-send


--
Michael Tosch @ hp : com
Michael Heiming

2007-05-21, 7:26 pm

In comp.unix.admin Michael Tosch <eedmit@no.eed.spam.ericsson.pls.se>:
> Michael Heiming wrote:
[vbcol=seagreen]
^^^^^^^[vbcol=seagreen]
[..][vbcol=seagreen]
[vbcol=seagreen]
> Please omit the "-" in BSD options (and have "-" in SysV options);
> I have seen a Linux ps that otherwise sais "depreciated".


> aux is BSD:


Indeed, I just copied it from the OP.

> ps aux | awk '$NF=="qmails-send" {print $2}'


> Some systems have pgrep:


> pgrep -x qmail-send


--
Michael Heiming (X-PGP-Sig > GPG-Key ID: EDD27B94)
mail: echo zvpunry@urvzvat.qr | PERL -pe 'y/a-z/n-za-m/'
#bofh excuse 142: new guy cross-connected phone lines with ac
power bus.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com