grep - getting the process name with awk (when it's over a day old)

grep - getting the process name with awk (when it's over a day old)

Post by Carl DiPasqual » Tue, 17 Oct 2000 04:00:00



Is there a consistent way to grep out the process name (rwmts60) from
the following examples:

oracle 29229 1  0  Oct 12    ?     1:20 rwmts60 port-1234  (process over
1 day old)
oracle 29229 1  0  12:45:38  ?     1:20 rwmts60 port=1234  (new process
started today)

ps -ef | grep process_name | grep -v grep | awk '{print $8}' - finds
rwmts60 for line #1
ps -ef | grep process_name | grep -v grep | awk '{print $8}' - finds
1:20 for example #2

thanks!

Carl DiPasquale
Oracle DBA
Visteon Corporation

 
 
 

grep - getting the process name with awk (when it's over a day old)

Post by Chuck Dillo » Tue, 17 Oct 2000 04:00:00


How about...

ps -ef | grep process_name | grep -v grep | awk '{ if (match($8,".*:.*") == 0) print $8;else print $9; }'

-- ced


> Is there a consistent way to grep out the process name (rwmts60) from
> the following examples:

> oracle 29229 1  0  Oct 12    ?     1:20 rwmts60 port-1234  (process over
> 1 day old)
> oracle 29229 1  0  12:45:38  ?     1:20 rwmts60 port=1234  (new process
> started today)

> ps -ef | grep process_name | grep -v grep | awk '{print $8}' - finds
> rwmts60 for line #1
> ps -ef | grep process_name | grep -v grep | awk '{print $8}' - finds
> 1:20 for example #2

> thanks!

> Carl DiPasquale
> Oracle DBA
> Visteon Corporation


--
Chuck Dillon
Senior Software Engineer
Genetics Computer Group, a subsidiary of Pharmacopeia, Inc.

 
 
 

grep - getting the process name with awk (when it's over a day old)

Post by Derek M. Fly » Tue, 17 Oct 2000 04:00:00



> How about...

> ps -ef | grep process_name | grep -v grep | awk '{ if (match($8,".*:.*") == 0) print $8;else print $9; }'

You could also use cut since the column position is the same regardless
of which format is used for the date.  Or your ps might let you be more
specific about which fields you actually intend to use.
 
 
 

grep - getting the process name with awk (when it's over a day old)

Post by Chuck Dillo » Tue, 17 Oct 2000 04:00:00




> > How about...

> > ps -ef | grep process_name | grep -v grep | awk '{ if (match($8,".*:.*") == 0) print $8;else print $9; }'

> You could also use cut since the column position is the same regardless
> of which format is used for the date.  Or your ps might let you be more
> specific about which fields you actually intend to use.

Sure and you could use sed to remove all forms of the STIME column and
print $7.

I avoid using cut in that way, IOW assuming nothing will shift even
one char, that is too fragile for my taste.

-- ced

--
Chuck Dillon
Senior Software Engineer
Genetics Computer Group, a subsidiary of Pharmacopeia, Inc.

 
 
 

grep - getting the process name with awk (when it's over a day old)

Post by Derek M. Fly » Wed, 18 Oct 2000 10:26:51



> > > ps -ef | grep process_name | grep -v grep | awk '{ if (match($8,".*:.*") == 0) print $8;else print $9; }'

> > You could also use cut since the column position is the same regardless
> > of which format is used for the date.  Or your ps might let you be more
> > specific about which fields you actually intend to use.

> Sure and you could use sed to remove all forms of the STIME column and
> print $7.

> I avoid using cut in that way, IOW assuming nothing will shift even
> one char, that is too fragile for my taste.

This is an excellent point.  Notice that your damned either way; if a
process had a colon anywhere in the command, your solution would match
on it, too.  Sometimes its quite difficult to know which way is more
prone to breaking ...
 
 
 

grep - getting the process name with awk (when it's over a day old)

Post by Tony R. Benne » Wed, 18 Oct 2000 04:00:00





>> > > ps -ef | grep process_name | grep -v grep | awk '{ if (match($8,".*:.*") == 0) print $8;else print $9; }'

>> > You could also use cut since the column position is the same regardless
>> > of which format is used for the date.  Or your ps might let you be more
>> > specific about which fields you actually intend to use.

>> Sure and you could use sed to remove all forms of the STIME column and
>> print $7.

>> I avoid using cut in that way, IOW assuming nothing will shift even
>> one char, that is too fragile for my taste.

>This is an excellent point.  Notice that your damned either way; if a
>process had a colon anywhere in the command, your solution would match
>on it, too.  Sometimes its quite difficult to know which way is more
>prone to breaking ...

Did the original poster ever say which version of *nix was being used???

I ask because on AIX there is the '-F' option... and on Sun (and in
POSIX-98) there is the '-o' option...

Both of these options allow you to specify which 'ps fields' are
displayed and in what order you want them displayed...
...in which case you could specify the 'CMD' to appear first, the 'pid'
next, etc.....  That way your 'awk could grab the first field '$1'...

Unfortunately, linux doesn't have that option... (at least not in
RedHat5.2...the only versions available to me)

HTH,
-tony

--


 
 
 

grep - getting the process name with awk (when it's over a day old)

Post by Chuck Dillo » Wed, 18 Oct 2000 04:00:00



> This is an excellent point.  Notice that your damned either way; if a
> process had a colon anywhere in the command, your solution would match
> on it, too.  Sometimes its quite difficult to know which way is more
> prone to breaking ...

Agreed.  However, I only gave an example.  If it were I, and I needed a
robust solution, I would use regular expressions to match everything
that preceeds the command, taking both forms into account.  For example,
I might use sed to remove the stuff I don't want with one or more REs
that handle the known forms of the output.  The REs could be general
enough to avoid column width variances.

-- ced

--
Chuck Dillon
Senior Software Engineer
Genetics Computer Group, a subsidiary of Pharmacopeia, Inc.

 
 
 

grep - getting the process name with awk (when it's over a day old)

Post by Carl DiPasqual » Wed, 18 Oct 2000 04:00:00


Unix flavor is HP-UX 11.0.

Carl





> >> > > ps -ef | grep process_name | grep -v grep | awk '{ if (match($8,".*:.*") == 0) print $8;else print $9; }'

> >> > You could also use cut since the column position is the same regardless
> >> > of which format is used for the date.  Or your ps might let you be more
> >> > specific about which fields you actually intend to use.

> >> Sure and you could use sed to remove all forms of the STIME column and
> >> print $7.

> >> I avoid using cut in that way, IOW assuming nothing will shift even
> >> one char, that is too fragile for my taste.

> >This is an excellent point.  Notice that your damned either way; if a
> >process had a colon anywhere in the command, your solution would match
> >on it, too.  Sometimes its quite difficult to know which way is more
> >prone to breaking ...

> Did the original poster ever say which version of *nix was being used???

> I ask because on AIX there is the '-F' option... and on Sun (and in
> POSIX-98) there is the '-o' option...

> Both of these options allow you to specify which 'ps fields' are
> displayed and in what order you want them displayed...
> ...in which case you could specify the 'CMD' to appear first, the 'pid'
> next, etc.....  That way your 'awk could grab the first field '$1'...

> Unfortunately, linux doesn't have that option... (at least not in
> RedHat5.2...the only versions available to me)

> HTH,
> -tony

> --



 
 
 

grep - getting the process name with awk (when it's over a day old)

Post by Tony R. Benne » Thu, 19 Oct 2000 04:00:00




Quote:>Unix flavor is HP-UX 11.0.

>Carl

does the man page show a '-o' or a '-F' option for 'ps' ???

-tony

 >>



 >> >> > >
 >> >> > > ps -ef | grep process_name | grep -v grep |
 >> >> > >    awk '{ if (match($8,".*:.*") == 0) print $8;else print $9; }'
 >> >> > >
 >> >> >
 >> >> >You could also use cut since the column position is the same regardless
 >> >> >of which format is used for the date.  Or your ps might let you be more
 >> >> >specific about which fields you actually intend to use.
 >> >>
 >> >> Sure and you could use sed to remove all forms of the STIME column and
 >> >> print $7.
 >> >>
 >> >> I avoid using cut in that way, IOW assuming nothing will shift even
 >> >> one char, that is too fragile for my taste.
 >> >
 >> >This is an excellent point.  Notice that your damned either way; if a
 >> >process had a colon anywhere in the command, your solution would match
 >> >on it, too.  Sometimes its quite difficult to know which way is more
 >> >prone to breaking ...
 >> >
 >>
 >> Did the original poster ever say which version of *nix was being used???
 >>
 >> I ask because on AIX there is the '-F' option... and on Sun (and in
 >> POSIX-98) there is the '-o' option...
 >>
 >> Both of these options allow you to specify which 'ps fields' are
 >> displayed and in what order you want them displayed...
 >> ...in which case you could specify the 'CMD' to appear first, the 'pid'
 >> next, etc.....  That way your 'awk could grab the first field '$1'...
 >>
 >> Unfortunately, linux doesn't have that option... (at least not in
 >> RedHat5.2...the only versions available to me)
 >>
 >> HTH,
 >> -tony
 >>
 >> --
--


 
 
 

grep - getting the process name with awk (when it's over a day old)

Post by atul.. » Fri, 20 Oct 2000 09:43:11




Quote:> Is there a consistent way to grep out the

process name (rwmts60) from
Quote:> the following examples:

> oracle 29229 1  0  Oct 12    ?     1:20 rwmts60

port-1234  (process over
Quote:> 1 day old)
> oracle 29229 1  0  12:45:38  ?     1:20 rwmts60

port=1234  (new process
Quote:> started today)

> ps -ef | grep process_name | grep -v grep |

awk '{print $8}' - finds
Quote:> rwmts60 for line #1
> ps -ef | grep process_name | grep -v grep |

awk '{print $8}' - finds

> 1:20 for example #2

> thanks!

> Carl DiPasquale
> Oracle DBA
> Visteon Corporation


Carl,

Please check if the following works:
ps -ef | grep process_name | grep -v grep |
awk '{print $(NF-2)}'

Atul.

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

grep - getting the process name with awk (when it's over a day old)

Post by Warren Da » Fri, 20 Oct 2000 11:49:40





>> Is there a consistent way to grep out the
>process name (rwmts60) from
>> the following examples:

>> oracle 29229 1  0  Oct 12    ?     1:20 rwmts60
>port-1234  (process over
>> 1 day old)
>> oracle 29229 1  0  12:45:38  ?     1:20 rwmts60
>port=1234  (new process
>> started today)

>> ps -ef | grep process_name | grep -v grep |
>awk '{print $8}' - finds
>> rwmts60 for line #1
>> ps -ef | grep process_name | grep -v grep |
>awk '{print $8}' - finds
>> 1:20 for example #2

>> thanks!

>> Carl DiPasquale
>> Oracle DBA
>> Visteon Corporation

>Carl,

>Please check if the following works:
>ps -ef | grep process_name | grep -v grep |
>awk '{print $(NF-2)}'

>Atul.

Sometimes this "trick" is useful:
    ps -ef | grep '[p]rocess_name' | grep awk '{print $(NF-2)}'
 
 
 

grep - getting the process name with awk (when it's over a day old)

Post by Carl DiPasqual » Fri, 20 Oct 2000 04:00:00



> does the man page show a '-o' or a '-F' option for 'ps' ???

Tony,

Unfortunately, no.  The only args seem to be:

ps [-edaflP] [-u ulist] [-g glist] [-p plist] [-t tlist] [-R prmgroup]

The XPG4 environment has a few more such as [-C cmdlist] and [-o
format], but that doesn't really
help.  The first post replay using the 'match' does work for my needs,
however, since I don't have the ':' character being used in any of my
processes.  Many thanks to Chuck Dillon and the rest who
have contributed to this thread so far.

Carl




> >Unix flavor is HP-UX 11.0.

> >Carl

> does the man page show a '-o' or a '-F' option for 'ps' ???

> -tony




>  >> >> > > ps -ef | grep process_name | grep -v grep |
>  >> >> > >    awk '{ if (match($8,".*:.*") == 0) print $8;else print $9; }'

>  >> >> >You could also use cut since the column position is the same regardless
>  >> >> >of which format is used for the date.  Or your ps might let you be more
>  >> >> >specific about which fields you actually intend to use.

>  >> >> Sure and you could use sed to remove all forms of the STIME column and
>  >> >> print $7.

>  >> >> I avoid using cut in that way, IOW assuming nothing will shift even
>  >> >> one char, that is too fragile for my taste.

>  >> >This is an excellent point.  Notice that your damned either way; if a
>  >> >process had a colon anywhere in the command, your solution would match
>  >> >on it, too.  Sometimes its quite difficult to know which way is more
>  >> >prone to breaking ...

>  >> Did the original poster ever say which version of *nix was being used???

>  >> I ask because on AIX there is the '-F' option... and on Sun (and in
>  >> POSIX-98) there is the '-o' option...

>  >> Both of these options allow you to specify which 'ps fields' are
>  >> displayed and in what order you want them displayed...
>  >> ...in which case you could specify the 'CMD' to appear first, the 'pid'
>  >> next, etc.....  That way your 'awk could grab the first field '$1'...

>  >> Unfortunately, linux doesn't have that option... (at least not in
>  >> RedHat5.2...the only versions available to me)

>  >> HTH,
>  >> -tony

>  >> --
> --



 
 
 

grep - getting the process name with awk (when it's over a day old)

Post by Dan Merc » Sat, 21 Oct 2000 04:00:00





>> does the man page show a '-o' or a '-F' option for 'ps' ???

> Tony,

> Unfortunately, no.  The only args seem to be:

> ps [-edaflP] [-u ulist] [-g glist] [-p plist] [-t tlist] [-R prmgroup]

> The XPG4 environment has a few more such as [-C cmdlist] and [-o
> format], but that doesn't really
> help.  The first post replay using the 'match' does work for my needs,
> however, since I don't have the ':' character being used in any of my
> processes.  Many thanks to Chuck Dillon and the rest who
> have contributed to this thread so far.

> Carl

I guess the confusing part is you already have the process name,
so why are you tring to awk out the process name?  Since you are on
HP-UX 11.0,  you should be able to find just about everything you need
from the XPG4 environment.  For instance:

   $ pids=$(UNIX95=1 ps -u oracle -C rwmts60 -o pid=)

But without a real clear idea of what you're after,  I can't advise
you further.

--
Dan Mercer

Opinions expressed herein are my own and may not represent those of my employer.

 
 
 

1. grep - getting the process name with awk (when it's over a day old)

Is there a consistent way to grep out the process name (rwmts60) from
the following examples:

oracle 29229 1  0  Oct 12    ?     1:20 rwmts60 port-1234  (process over
1 day old)
oracle 29229 1  0  12:45:38  ?     1:20 rwmts60 port=1234  (new process
started today)

ps -ef | grep process_name | grep -v grep | awk '{print $8}' - finds
rwmts60 for line #1
ps -ef | grep process_name | grep -v grep | awk '{print $8}' - finds
1:20 for example #2

thanks!

Carl DiPasquale
Oracle DBA
Visteon Corporation

2. Is a proxy server supposed to remove base64 encoding?

3. Problems installing

4. Problems with DNS/named 'remembering' old machine names

5. Netscape 4.51 aborts on starting Java

6. change group name and gid for all files of given old group name or old gid

7. problem with libutil

8. kill -9 `ps -u`whoami` | grep $1 | awk '{print $1}'`

9. Using perl/shell scripts to kill processes more than x days old

10. Getting A Day Using AWK or A Shell Script

11. awk '{gsub("old","\n"); print}' adds additional new line

12. Script to display processes which are more than 2 days old.