grep format assistance required
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix administration > grep format assistance required




Pages (2): [1] 2 »   Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    grep format assistance required  
Tribeguy 15


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-13-07 12:17 AM

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







[ Post a follow-up to this message ]



    Re: grep format assistance required  
Bit Twister


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-13-07 12:17 AM

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






[ Post a follow-up to this message ]



    Re: grep format assistance required  
Tribeguy 15


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-13-07 12:17 AM

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






[ Post a follow-up to this message ]



    Re: grep format assistance required  
Chris F.A. Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-13-07 12:17 AM

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





[ Post a follow-up to this message ]



    Re: grep format assistance required  
Michael Heiming


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-14-07 12:24 AM

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





[ Post a follow-up to this message ]



    Re: grep format assistance required  
Jean-Rene David


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-14-07 06: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





[ Post a follow-up to this message ]



    Re: grep format assistance required  
Brian Beuchaw


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-15-07 12:18 AM

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





[ Post a follow-up to this message ]



    Re: grep format assistance required  
Tribeguy 15


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-15-07 12:18 AM

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





[ Post a follow-up to this message ]



    Re: grep format assistance required  
Dave Hinz


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-15-07 12:18 AM

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.






[ Post a follow-up to this message ]



    Re: grep format assistance required  
Tribeguy 15


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-15-07 06: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> w
rote: 
>
>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





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:25 AM.      Post New Thread    Post A Reply      
Pages (2): [1] 2 »   Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register