System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Reg Bill's adminalert.sh script

 
SOLVED
Go to solution
chindi
Respected Contributor

Reg Bill's adminalert.sh script

Hi Bill ,

 

Its an excellent script.

But somehow its not running for one of my process .

 

ps -ef |grep -i str F0004

 

test 28899 1 0 13:31:02 pts/3 0:00 str F0004
rte 28254 1 0 May 21 ? 0:01 str F0004
dfr 3509 16295 1 15:58:12 pts/0 0:00 grep -i F0004
ddk17349 1 0 May 21 ? 0:04 str F0004

 

when am mentioning ;

ProcMon=1
PROCS=F0004:1:2

 

Where do i put second argument "str" ??

 

11 REPLIES
Patrick Wallek
Honored Contributor

Re: Reg Bill's adminalert.sh script

According to your 'ps' output the script that is running is actually 'str' and the first argument to 'str' is F0004.

 

However, if you are wanting to check to make sure 'str F0004' is running, I'm not sure how to do that.  I don't know that Bill designed the script to handle spaces in the process name(s) it is looking for.

 

I sent Bill an e-mail alerting him to your question.

pooderbill
Valued Contributor

Re: Reg Bill's adminalert.sh script

There is no process named "str F0004"

The process name is str as reported by ps.

The string "F0004" is just an argument. There is no provision to look for a process and then look for arguments.

 

The correct entry would be:

 

ProcMon=1
PROCS=str:1:2

 

which will email a message if "str" is not running, or there are more than 2 copies running.

chindi
Respected Contributor

Re: Reg Bill's adminalert.sh script

 Thanks Patrick :-)

chindi
Respected Contributor

Re: Reg Bill's adminalert.sh script

Hi Pooderbill,

 

I need to grep F0004 primarily , not str .

Bill Hassell
Honored Contributor
Solution

Re: Reg Bill's adminalert.sh script

So F0004 might appear on the command line for multiple programs?

 

As a reminder, grep and ps can be an unstable combination. grep matches any string of characters, anywhere on the ps line. That means that a user named F0004 will be found, an argument on a command line such as A:AFF000423, and of course the grep command itself which will have F0004 on the command line.

 

To narrow down the search (and make it more accurate), I would use the UNIX95=1 feature to enable these extra options:

 

-C <process name(s)>

-H to parent/child relationships

-o <columns to list>

 

The two options for this task would be -C to list only the processes that might have F0004 on the command line, and -o which allows you to customize the output for easier scripting.

 

Let's assume that there are 3 different processes that might have F0004, str, strabc and abc. To find exactly those processes by name, NEVER use grep but rather, use this:

 

UNIX95=1 ps -f -C str,strabc,abc

 

This will not find processes like abc123 or str2, only exact name matches.

Now that you have only the programs to be tested, you can then choose which columns to have displayed by ps.

This is done with the -o option. For example:

 

# UNIX95=1 ps -C httpd -o pid -o args
  PID COMMAND
 4282 /opt/hpws/apache/bin/httpd -d /opt/hpws/apache -k start
 4279 /opt/hpws/apache/bin/httpd -d /opt/hpws/apache -k start
 4364 /opt/hpws/apache/bin/httpd -d /opt/hpws/apache -k start
 4363 /opt/hpws/apache/bin/httpd -d /opt/hpws/apache -k start

and without a title line:

# UNIX95=1 ps -C httpd -o pid= -o args=
 4282 /opt/hpws/apache/bin/httpd -d /opt/hpws/apache -k start
 4279 /opt/hpws/apache/bin/httpd -d /opt/hpws/apache -k start
 4364 /opt/hpws/apache/bin/httpd -d /opt/hpws/apache -k start
 4363 /opt/hpws/apache/bin/httpd -d /opt/hpws/apache -k start

The UNIX95=1 is a temporary assignment just for the ps command.

Don't assign the variable on a separate line as this change the behavior of other commands.

 

The column names are listed in the man page.

 

To eliminate the title line, set the column name to nothing or use "" as in pid= or pid=""

If all you need is the PID, then this is the easiest way. Now you can grep F0004 from just the listed processes.

 

# UNIX95=1 ps -C str,strabc,abc -o pid= -o args= | grep F0004
17546 str F00004
12789 abc -a "zz43 F0004" -w ww9

(Note for the purists: UNIX95=1 can be just UNIX95= in order to define the variable. See man 5 standards)



Bill Hassell, sysadmin
chindi
Respected Contributor

Re: Reg Bill's adminalert.sh script

Hi Bill ,

 

So where exactly i need to make changes ? to grep F0004 alongwith str ??

Will you please help me with it .

Bill Hassell
Honored Contributor

Re: Reg Bill's adminalert.sh script

My script will not work for your requirement.

You'll need to create a script that performs the monitoring using ps and grep for F0004, then add logic to see if it meets your requirements.



Bill Hassell, sysadmin
chindi
Respected Contributor

Re: Reg Bill's adminalert.sh script

Oh :( .

Anyway thanks for the hint.

Will check it.

Steven Schweda
Honored Contributor

Re: Reg Bill's adminalert.sh script

> There is no process named "str F0004"
> The process name is str as reported by ps.

 

   Does the concept of a "process name" even exist on UNIX?  It does on
VMS (where a process name may have little or nothing to do with the
executable being run).  For example, given a process ID, one can request
its name (using the Get Job and Process Information service):

 

      alp $ write sys$output f$getjpi( "20200410", "PRCNAM")
      AUDIT_SERVER

 

   On UNIX, one can pretend that argv[0] is a process name, but, because
multiple processes can run the same executable, multiple processes can
have the same "name" (argv[0]), so this "name" does not uniquely
identify a process.  Even on VMS, a process name is unique only within
a process group, but it's a better identifier there than argv[0] is on
UNIX.

 

    "man ps" mentions "args", "arguments", and "command name", but I
don't see "process name" anywhere.

chindi
Respected Contributor

Re: Reg Bill's adminalert.sh script

Hi Steven ,

 

So are you saying that its possible by Bill's script ?

Or need to modify it as per my requirement ?

Dennis Handly
Acclaimed Contributor

Re: Regarding Bill's adminalert.sh script

>Or need to modify it as per my requirement?

 

The latter, you need to modify it.