Operating System - HP-UX
1748061 Members
5442 Online
108758 Solutions
New Discussion юеВ

Re: script to find specific username and command hpux 11.23

 
SOLVED
Go to solution
Donald Thaler
Super Advisor

script to find specific username and command hpux 11.23

is there a script available that will let me see what processes are running based on a specific username and command.... from the top command i get a listing of processes that are running and it shows the username and the command, i would like to list out those processes that have a username of "oracle" and a command value of "oracleLCCC"..
8 REPLIES 8
Pete Randall
Outstanding Contributor

Re: script to find specific username and command hpux 11.23

I think what you're looking for are the XPG4 options available with the ps command, as in

UNIX95= ps -C(cmdlist) -U(uidlist)


Pete

Pete
James R. Ferguson
Acclaimed Contributor

Re: script to find specific username and command hpux 11.23

Hi Donald:

You could use 'ps' under the 'UNIX95' (or XPG4) behavior like this:

# UNIX95= ps -C oracleLCCC -o pid= -o user= | grep oracle

This finds all processes with a basename of "oracleLCCC" and lists (sithout headings) their 'pid' and effective login name ('user').

Note the white space after 'UNIX95='. This causes the variable to be set only for the duration of the command line.

Regards!

...JRF...

Bill Hassell
Honored Contributor
Solution

Re: script to find specific username and command hpux 11.23

The ps command has several extended options that are activated with the existence of the UNIX95 variable. -C will allow selecting processes by name (technically, by basename regardless of the pathname used to start the process). And -U is an extension to -u to allow either the user id number or username. Unfortunately, the two commands inclusive, that is, -U oracle will show all oracle-owned processes, but -C oracleLCCC will not reduce the list to just the oracleLCCC processes owned by oracle.

For your example, the process oracleLCCC is probably run only by the oracle user so this command is sufficient:

UNIX95=1 ps -C oracleLCCC

The command:

UNIX95=1 ps -U oracle

will find all processes owned by the user oracle. Using the UNIX95=1 variable and the extended options (man ps) will eliminate the mistakes made when combining ps and grep together.


Bill Hassell, sysadmin
James R. Ferguson
Acclaimed Contributor

Re: script to find specific username and command hpux 11.23

Hi (again) Donald:

We had a lively discussion about how best to arm the UNIX95 behavior here:

http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1276190

You can note that any of the following will *set* the behavior:

# UNIX95=
#UNIX95=1
# UNIX95=EXTENDED_PS_FEATURES
#UNIX95=0

The last line suggests that 'UNIX95=0' might turn off the XPG (UNIX95) behavior. This is *NOT* true. The action 'UNIX95= ' or 'UNIX95=0' or 'UNIX95=1' equally result in an defined value which toggles the XPG behavior. Simply compare:

# UNIX95= ps -C sh
# UNIX95=0 ps -C sh
# UNIX95=1 ps -c sh

...and you will see no difference.

Regards!

...JRF...
Donald Thaler
Super Advisor

Re: script to find specific username and command hpux 11.23

the commands listed ellicited the following results:

UNIX95= ps -C oracleLCCC -o pid= -o user= | grep oracle >> nothing


UNIX95=1 ps -C oracleLCCC >>> # UNIX95=1 ps -C oracleLCCC
PID TTY TIME CMD


UNIX95=1 ps -U oracle >> listad all processes owned by oracle

is there some reason the

UNIX95= ps -C oracleLCCC -o pid= -o user= | grep oracle command doesn't return anything ??
James R. Ferguson
Acclaimed Contributor

Re: script to find specific username and command hpux 11.23

Hi (again) Donald:

> is there some reason the

UNIX95= ps -C oracleLCCC -o pid= -o user= | grep oracle command doesn't return anything ??

The '-C oracleLCCC' assumes that the *basename* of the command is "oracleLCCC". If by "command" you meant somewhere in the whole command line, match this, then you might do something like:

# UNIX95= ps -e -opid= -ocomm= -ouser= | awk '$2~/oracleLCCC/ && $3~/oracle/'

If the token "oracleLCCC" is an argument to a process of another basename, use:

# UNIX95= ps -e -opid= -oargs = -ouser= | awk '$2~/oracleLCCC/ && $3~/oracle/'

By the way, when you get to 11.31 have a look at 'pgrep(1)' :-)

Regards!

...JRF...
Bill Hassell
Honored Contributor

Re: script to find specific username and command hpux 11.23

> UNIX95= ps -C oracleLCCC -o pid= -o user= | grep oracle >> nothing

Since grep doesn't care whether the string is oracle or oracleLCCC, this would indicate that there is no process by the name "oracleLCCC". Spelling counts in the -C option. Do this instead:

UNIX95= ps -U oracle -opid= -o user= -o comm=

Now you will see all the processes by name that are owned by oracle. Change -o comm= to -o args= and you'll see the command line.

The -C is an exact match for the process name -- no pathnames, no arguments, etc. To see if there is anything like LCCC, do this:

UNIX95= ps -U oracle -opid= -o user= -o args= | grep -i LCCC

There may be a special character in the process name (yuk) so if you see the process with -U oracle but grep can't find it, pipe the output to cat -tv and look for garbage characters:

UNIX95= ps -U oracle -opid= -o user= -o comm= | vis

And just to clarify, UNIX95 is a temporary variable whose contents is unimportant. That's why UNIX95= (which is null) and UNIX95=0 (which has a value) produces the same result. As long as UNIX95 has a value, ps will enable the extended options.


Bill Hassell, sysadmin
Dennis Handly
Acclaimed Contributor

Re: script to find specific username and command hpux 11.23

You can start with a hierarchical dump then refine it with grep:
UNIX95=EXTENDED_PS ps -H -fu oracle