Operating System - HP-UX
1836648 Members
1936 Online
110102 Solutions
New Discussion

Re: script to run a process....

 
SOLVED
Go to solution
praveen..
Super Advisor

script to run a process....

Hi,
One of my process goes to stop, i dont know why.
and this effect to our production.

I can check this process using this command:
# ps -ef | grep -i java*
root 3842 3820 0 06:24:21 pts/3 0:00 grep -i java
jsusr01 24904 24898 0 01:14:19 ? 0:23 /opt/java1.4/bin/IA64N/java -cp .:/apps/LoyAn/k2_test/JetQueryWebListener/latest/config:/apps/LoyAn/k2_test/JetQueryWebListener


and if it not there, then i need to start this process using:

#nohup ./runRequestListener.sh 2> /apps/LoyAn/share/JetQuery/requestListener.err 1>/dev/null&

so I want to write this script which will monitor whether this process is running or not?
if not, this script will start this process and email me for the notification.

I am able to get the emails from this server using mailx command.

Please suggest
6 REPLIES 6
spex
Honored Contributor

Re: script to run a process....

Hi,

There are many ways to do this. One way is to cron the following:

#!/usr/bin/sh
# cd /runRequestListener.sh_dir
[ -z "$(UNIX95= ps -C java -o pid= -o comm=)" ] && mailx -m -s "java is not running" root && nohup ./runRequestListener.sh 2>> /apps/LoyAn/share/JetQuery/requestListener.err 1>> /dev/null &
exit 0

PCS
praveen..
Super Advisor

Re: script to run a process....

please suggest
RAC_1
Honored Contributor

Re: script to run a process....

Somthing like follows in cron tab.

#!/usr/bin/ksh

proc_pid=$(UNIX95= ps -C"process_name" -o pid|grep -v PID)

kill -0 ${proc_pid} || "code_to_start_process"
There is no substitute to HARDWORK
praveen..
Super Advisor

Re: script to run a process....

Hi RAC,
can you please tell me what will 1st line do and what will 2nd line do?

why i need to kill the process,

i need to start this process if it is not running

Thanks
inventsekar_1
Respected Contributor
Solution

Re: script to run a process....

Hi Praveen,

proc_pid=$(UNIX95= ps -C"process_name" -o pid|grep -v PID)

kill -0 ${proc_pid} || "code_to_start_process"


first line:
used to get the PID of the "process_name".

second line:
kill -0 will "access to PID".
>> SIGNULL (0), the null signal, invokes error checking but no signal is
actually sent. This can be used to test the validity or existence of
pid.

if that is okay, then ""code_to_start_process" in that place, code to start the process should go. that is this part:
nohup ./runRequestListener.sh 2> /apps/LoyAn/share/JetQuery/requestListener.err 1>/dev/null&


so, in the second line ur not killing the process. just checking that.
Be Tomorrow, Today.
Arturo Galbiati
Esteemed Contributor

Re: script to run a process....

Hi,
you can use:

#/usr/bin/ksh
NUM_PROC=$(ps -fu jsusr01|grep -c [j]ava)
if [[ $NUM_PROC = 0 ]]
then
nohup ./runRequestListener.sh 2> /apps/LoyAn/share/JetQuery/requestListener.err 1>/dev/null &
fi
#eof

please note that I use -u option to be sure that the java process is for teh rigth user.


HTH,
Art