Operating System - HP-UX
1829904 Members
2492 Online
109993 Solutions
New Discussion

Shell Script checking processes

 
SOLVED
Go to solution

Shell Script checking processes

Hi everybody, haven´t been able to come up with a decent shell script to do this for me:
For a few servers running OS=HP-UX 11.0

1. Check on processes running from a file, third column of a file
2. If running do nothing (and if was previously "not running" send e-mail saying is UP again and exit, once it has notified, don't bother to inform again!).
3. If not running, send e-mail to inform (keep the status to check on next run if process came up).

Hope I was "crystal clear" on my question!
Does anybody have such a script?, since I believe must be a common issue actually, any help would be greatly appreciated.
Couldn't get it to work properly myself.
Thanks a lot
The end of wisdom is freedom. The end of culture is perfection. The end of education is character. The end of knowledge is love.
10 REPLIES 10
Graham Cameron_1
Honored Contributor

Re: Shell Script checking processes

www.bb4.com

-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
Todd McDaniel_1
Honored Contributor

Re: Shell Script checking processes

Here is a rudementary script that will handle one process. You can expand it to cover more than one.

Where $VAL -ge 1, the 1 is the number of procs you are validating are supposed to be running. In my case the number is 4, but for you maybe only 1

-------------------------------------------
VAL=0
echo $VAL

VAL=`ps -aef|grep |grep -v grep|grep -v <scriptname> |wc -l`

echo $VAL
if [ $VAL -ge 1 ]
then echo "Services are running";ps -aef|grep -e -e opl |grep -v
grep|grep -v <scriptname>;date
else mailx -s "Services" root < /root/process.notice
fi
--------------------------------------------
Unix, the other white meat.

Re: Shell Script checking processes

Thanks a lot Graham, actually I'm a HP-OVO's admin, the weird thing about it, is our Operations staff won't consider OV's notifications good enough, and would like to have mail notifications (for processes down) and a single notification whenever a process comes up again.
I'm already using opcmsg to accomplish part of it, but OP would like e-mail notifications.

Thanks again.
The end of wisdom is freedom. The end of culture is perfection. The end of education is character. The end of knowledge is love.
Michael Schulte zur Sur
Honored Contributor
Solution

Re: Shell Script checking processes

Hi,

here is another script.

greetings,

Michael

Re: Shell Script checking processes

Thanks a lot Todd and Michael!
Todd, your script works great, had my own script working close to that, but still doesn't provide with the information/status, regarding whenever a process previously was DOWN and now is back UP again, I did test it but didn't seem to work that way.

Now, Michael, yours works great, but seems I really have a problem getting correctly the processes from my file, such as:

COMMAND=`cat /var/opt/OV/conf/OpC/procmon.conf | awk '{ print $3 }'`

Is there a better way to do this?A proper way?
Since this file /var/opt/OV/conf/OpC/procmon.conf looks like this:
1 OS inetd Exact 1 Critical 2
1 OS sshd Min 1 Critical 2

Any help is much appreciated guys, thanks for your quick and proper response.
Best regards.

The end of wisdom is freedom. The end of culture is perfection. The end of education is character. The end of knowledge is love.
Michael Schulte zur Sur
Honored Contributor

Re: Shell Script checking processes

Hi,

if you have more than one process in your config file, you have a problem.
try this

while read F1 F2 PROCESS F4 F5 F6
do
checkproc ${PROCESS} &
done < /var/opt/OV/conf/OpC/procmon.conf

greetings,

Michael
Michael Schulte zur Sur
Honored Contributor

Re: Shell Script checking processes

Hi,

I have redone my script.

greetings,

Michael

Re: Shell Script checking processes

Michael, just perfect!
I've only modified this:
"Min") COMPAREON[${NUMPROC}]="-eq";;
Replaced "-gt" with "-eq", so it notifies perfectly whenever a process comes up again.

I really appreciate guys your help, and even more, in such a short period of time!
Thanks again!
If there is a way to assign more point to you guys,let me know!

Best regards,
C.
The end of wisdom is freedom. The end of culture is perfection. The end of education is character. The end of knowledge is love.
Michael Schulte zur Sur
Honored Contributor

Re: Shell Script checking processes

Hi Carlos,

just curious, can you explain the meaning of the fields in the config file? I thought Min means minimum, so if 2 processes are running then the script will complain again. The script was designed to mail once, when the minimum number of processes are running. Am I missing something?

greetings,

Michael

Re: Shell Script checking processes

Hi Michael, yes, sure (this is a conf file I'm using for Openview's script, so, that is why I keep the same format):

1=check for process
OS=OS process
inetd=name of process
Exact=condition Min-Max or Exact
1=number of times running (Exact 1 time, Min 1 time) etc...
Critical=status IF down
2=frequency

And in order to e-mail once, had to add the following test:
else
test ${NOTIFIED[${COUNT}]}="YES" && echo "Service down...etc...

This way it only sends one e-mail to notify for a process DOWN, and only one e-amil to notify a process is UP again, works great!
Thanks again!

Best regards,
C.
The end of wisdom is freedom. The end of culture is perfection. The end of education is character. The end of knowledge is love.