Re: piping unknown number of elements to an array
From: Barry Margolin (barry.margolin_at_level3.com)
Date: 04/29/03
- Next message: Solaris Boy: "Re: cannot su to root"
- Previous message: Cheryl: "Re: Shell scripting help required..."
- In reply to: brfg3: "piping unknown number of elements to an array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Tue, 29 Apr 2003 17:50:47 GMT
In article <KPadnY5e7dx5PzOjXTWcpw@giganews.com>, <brfg3> wrote:
>I need to write a script that monitors our postfix. When I ps -aux | grep
>"postfix"
>I get a bunch of entries. All I need is the last field, so I changed to ps -aux |
>grep "postfix" | awk '{print $11}' which gives me the last field. The problem is
>that there are many postfix processes, and I really don't know which one is the
>actual postfix daemon and which are forked processes, but I do know that
>if postfix
>is down, nothing shows except the grep statement.
>
>example:
>[root@mailserver root]# ps -aux | grep "postfix" | awk '{print $11}'
>qmgr
>proxymap
>trivial-rewrite
>smtpd
>local
>local
>smtpd
>cleanup
>grep
>
>What I want to do is load each of these lines into an array so I can loop through
>and decide if the array has a running postfix in it or just my grep. How can I do
>that (pipe the output of "ps -aux | grep "postfix" | awk '{print $11}'" into an
>array without knowing how many elements the array will have?
Why do you need an array? Why not just exclude the unwanted ones with an
appropriate regexp?
ps -aux | awk '/postfix/ && !/awk/ {print $11}'
or
ps -aux | awk '/[p]ostfix/ {print $11}'
or if you insist on using grep even though awk has its own regexp matcher:
ps -aux | grep '[p]ostfix' | awk '{print $11}'
or
ps -aux | grep 'postfix' | grep -v grep | awk '{print $11}'
-- Barry Margolin, barry.margolin@level3.com Genuity Managed Services, a Level(3) Company, Woburn, MA *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups. Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
- Next message: Solaris Boy: "Re: cannot su to root"
- Previous message: Cheryl: "Re: Shell scripting help required..."
- In reply to: brfg3: "piping unknown number of elements to an array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|