Monitor and restart UNIX process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Monitor and restart UNIX process
# 1  
Old 09-03-2013
Monitor and restart UNIX process

Hi all,

Tearing my hair out..!

I have a requirement to monitor and restart a unix process via a simple watchdog script.

I have the following 3 scripts that dont work for me..

script 1 (only produces 1 output if process is up or not)
-----------------------------------------------------------------

Code:
#!/bin/bash

PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/kerberos/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin

ps cax | grep tnsrec > /dev/null
#echo $?
if [ $? -eq 1 ]; then
  bash /opt/oracle/scripts/tnsrec CP10C > tnsrec.log 2>&1 &
  exit
else
  exit
fi

script 2 (only produces 1 output if process is up or not)
-----------------------------------------------------------------

Code:
#!/bin/sh

PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/kerberos/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin

TNSPROC=`ps -ef|grep tnsrec | awk '{if ($8 !~ /grep/) print $2}'`

if ! [ -n "${TNSPROC}" ] ; then
  nohup /opt/oracle/scripts/tnsrec CP10C > tnsrec.log 2>&1 &
fi

exit 0

script 3 only produces 1 output..
--------------------------------------
Code:
#!/bin/bash

PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/kerberos/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin

ps -ef |grep -v grep | grep tnsrec > /dev/null 2>&1

case "$?" in
  0)
  true
  ;;
  1)
  bash /opt/oracle/scripts/tnsrec CP10C > tnsrec.log 2>&1 &
esac
exit

What am I doing wrong?

Any one any ideas for a simple watchdog script..

Thanks in advance,

jd
# 2  
Old 09-03-2013
Having said that, what is wrong here???
# 3  
Old 09-03-2013
none of the example working for me.
# 4  
Old 09-03-2013
Will this "nohup /opt/oracle/scripts/tnsrec CP10C > tnsrec.log 2>&1 &" work properly when u execute from commandline?
# 5  
Old 09-03-2013
I am assuming you are running with root? You should run these activities with oracle user.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to monitor some UNIX process and send notification in every 10 minutes?

Hi Unix Members, Can anyone guide me to write one shell script to monitor the attach screen processes and when interrupted mail us. , like the processes - /bin/ciserver , /bin/clock , /bin/cserver , /bin/main Please looking forward you guys help. (6 Replies)
Discussion started by: biswajitnitd
6 Replies

2. HP-UX

Critical Sevices and Process to be monitor on UNIX servers

Need to note the list of critical / important services and process need to monitor on unix server always with one line explanation for severity. Thanks in advance. (5 Replies)
Discussion started by: marunmeera
5 Replies

3. Shell Programming and Scripting

How do i restart a process if it fails?

Hi Guru's, I just want to have an idea on how to restart a particular step when it fails? SCENARIO we have plenty of steps such as the following below: Step 1 copy file from source to target location which is in a different server. Step 2 create initial and incremental process ... (4 Replies)
Discussion started by: reignangel2003
4 Replies

4. Shell Programming and Scripting

Script to restart process

HI, I am trying to write a scrip which would restart active process. This is what i have written till now. $ xms show pr PRESE.* NAME STATUS ROLE PID RSTRTS STARTED MACHINE... (8 Replies)
Discussion started by: Siddheshk
8 Replies

5. AIX

powerha application monitor restart counter?

I have configured a custom application monitor with restart count = 3. say the application has restarted 2 times, if the application fail 2 more times within restart interval, it will failover. Is there any counter to tell me the recent restart count? Thanks!! (1 Reply)
Discussion started by: skeyeung
1 Replies

6. Shell Programming and Scripting

Script to restart a process

I have written a script which checks for a file if that is being updated or not. If the files is not being updated then it will restart the process. #!/bin/sh DATE=`date +%Y%m%d%H%M%S` LOG_FILE=/var/xmp/log/XMP_* INCEPT=`ls -l $LOG_FILE |awk '{print $5}'` PROC=`xms show pr |grep -i... (3 Replies)
Discussion started by: Siddheshk
3 Replies

7. Shell Programming and Scripting

script to monitor the process system when a process from user takes longer than 15 min run.

get email notification from from system when a process from XXXX user takes longer than 15 min run.Let me know the time estimation for the same. hi ,any one please tell me , how to write a script to get email notification from system when a process from as mentioned above a xxxx user takes... (1 Reply)
Discussion started by: kirankrishna3
1 Replies

8. Shell Programming and Scripting

restart process based on file

Hi all. I do have a script "startApp.sh" (app result is a file /opt/extract/appextract.txt) I have no problems with stopping app var1=`ps -ef | grep -v grep | grep MyApp | awk '{print $2}'` kill -9 $var1 What I want to achieve is: I start app, app is doing some extraction, after... (11 Replies)
Discussion started by: e-l-diablo
11 Replies

9. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

Hello all, I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted. Thanks in advance Regards, pradeep kulkarni. :mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies

10. SuSE

Restart process

I have a process that gradually eats up memory, it's currently at 80.2% and slowing down the linux server > ps aux | grep SNMPME root 3129 0.0 80.2 3591752 2480700 ? Sl Feb13 5:04 /opt/nampe/lib/snmpme/SNMPME config/startup.xml Is there a command I can execute to restart this... (3 Replies)
Discussion started by: brendan76
3 Replies
Login or Register to Ask a Question