Operating System - HP-UX
1839969 Members
2587 Online
110157 Solutions
New Discussion

Looking for a better Unix Process Monitoring Script...

 
SOLVED
Go to solution
Vijaya Kumar_3
Respected Contributor

Looking for a better Unix Process Monitoring Script...

Greetings.

We are running a HP-UX Machine on PA/RISC Server. My "uname -r" command reveals that the version is B.11.23 and my "uname -m" command reveals that it is U 9000/800. This Server is running Peoplesoft Applications.

I want to write a script to monitor "BBL" processes, I am using the following command to check the existence of a process. If the count is 0, then I am sending an email to the administrator.

RC=$(ps -ef |grep BBL |grep $USER |grep $INSTANCE |grep -v grep |grep PSUNX|wc -l)

if [ $sendmail -eq 1 ];
then
$MAIL -s "BBL Service Down @ $(hostname)" $ADMINEMAIL
fi

(Note that Variables are already defined earlier.)

Now, the question, is it the same logic used by you? Do you have any other ideas?

Regards
Vijay Chinnasamy
Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com
10 REPLIES 10
Vijaya Kumar_3
Respected Contributor

Re: Looking for a better Unix Process Monitoring Script...

Oh.. I forgot to add.

I will assign points. Thank you in advance.

Regards
Vijay Chinnasamy
Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com
Pete Randall
Outstanding Contributor

Re: Looking for a better Unix Process Monitoring Script...

That seems adequate to me, yet you say you're looking for a "better" script. What sort of improvement are you looking for or where is this script lacking?


Pete

Pete
Tingli
Esteemed Contributor

Re: Looking for a better Unix Process Monitoring Script...

What are "grep $USER |grep $INSTANCE | grep PSUNX" those for?
James R. Ferguson
Acclaimed Contributor
Solution

Re: Looking for a better Unix Process Monitoring Script...

Hi Vijay:

Instead of all these 'grep's to discard false matches, use the UNIX95 (XPG4) behavior of 'ps' to grab _exactly_ the process by name you want.

For example, if I want information about the 'cron' caemon:

# UNIX95= ps -C cron -o pid,pid,user,vsz,time,comm

(or) if I don't want output with headings:

# UNIX95= ps -C cron -o pid= -o pid= -o user= -o vsz= -o time= -o comm=

Set the UNIX95 behavior only for the duration of the command line! Hence the space (no semicolon) after the '=' and before the 'ps' command.

See the 'ps' manpages for the arguments you can display with the '-o' format.

Regards!

...JRF...
Vijaya Kumar_3
Respected Contributor

Re: Looking for a better Unix Process Monitoring Script...

Probably I didn't provide my expectation. I need something like James provided. I am going to try the "UNIX95 ps" option. Becos I feel my command to check a process has some unnecessary complications...

Also, Here are the values and the complete script...

###################################

USER=c290100
INSTANCE=ORAC290
MAIL=/usr/bin/mailx

sendmail=$(ps -ef |grep BBL |grep $USER |grep $INSTANCE |grep -v grep |grep PSUNX|wc -l)

if [ $sendmail -eq 1 ];
then
$MAIL -s "BBL Service Down @ $(hostname)" $ADMINEMAIL
fi

###################################

Regards
Vijay Chinnasamy
Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com
Vijaya Kumar_3
Respected Contributor

Re: Looking for a better Unix Process Monitoring Script...

NOTE:

Points will be assigned later when I am ready to close the thread and got as many options possible...
Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com
Bill Hassell
Honored Contributor

Re: Looking for a better Unix Process Monitoring Script...

It's important to understand that grep and ps are a very unstable combination and will match thing that you don't want. ps will find an exact match for your process name. It doesn't look as if BBL is the process name. It would help immensely if you showed all the processes that might match BBL and then specify what criteria you need to match. Note also that wc is unnecessary -- grep -c will return the count for you.


Bill Hassell, sysadmin
Dennis Handly
Acclaimed Contributor

Re: Looking for a better Unix Process Monitoring Script...

>grep BBL | grep $USER | grep $INSTANCE | grep PSUNX

If you know the order of these various words, you can use one grep:
grep "BBL.*$USER.*$INSTANCE.*PSUNX"

Re: Looking for a better Unix Process Monitoring Script...

Hello,

1) You might save the 'wc -l' pipe using the -c option of the grep command which counts its results.

2) You might use the -u option of the ps command instead of -e :

ps -fu $USER

3) You might also save the 'grep -v grep' pipe by writting :

ps -fu $USER | grep '[B]BL' | ...

so that the 'grep BBL' process be not selected.

4) Except if you intend to reuse the value of the sendmail variable, you might save the use of this variable by directly writting sommething like :

if ! ps -fu $USER | egrep -q "[B]BL.*$INSTANCE.*PSNUX" ; then
$MAIL -s "BBL Service Down @ $(hostname)" $ADMINEMAIL
fi

Otherwise, taking into account Dennis' remark about the order of the words, I would write :

integer sendmail=$( ps -fu $USER | egrep -c "[B]BL.*$INSTANCE.*PSNUX" )

(( sendmail == 0 )) && $MAIL -s "BBL Service Down @ $(hostname)" $ADMINEMAIL

Cheers,

Jean-Philippe
Vijaya Kumar_3
Respected Contributor

Re: Looking for a better Unix Process Monitoring Script...

Thanks everyone, I learned a lot from this thread.


Regards
Vijay Chinnasamy
Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com