Sponsored Content
Top Forums Shell Programming and Scripting Monitor and restart UNIX process Post 302849773 by jonnyd on Tuesday 3rd of September 2013 09:30:20 AM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
service(8)						      System Manager's Manual							service(8)

NAME
service - run a System V init script SYNOPSIS
service SCRIPT COMMAND [OPTIONS] service --status-all service --help | -h | --version DESCRIPTION
service runs a System V init script in as predictable an environment as possible, removing most environment variables and with the current working directory set to /. The SCRIPT parameter specifies a System V init script, located in /etc/init.d/SCRIPT. The supported values of COMMAND depend on the invoked script. service passes COMMAND and OPTIONS to the init script unmodified. All scripts should support at least the start and stop commands. As a special case, if COMMAND is --full-restart, the script is run twice, first with the stop command, then with the start com- mand. service --status-all runs all init scripts, in alphabetical order, with the status command. EXIT CODES
service calls the init script and returns the status returned by it. FILES
/etc/init.d The directory containing System V init scripts. ENVIRONMENT
LANG, TERM The only environment variables passed to the init scripts. SEE ALSO
/etc/init.d/skeleton, update-rc.d(8), init(8), invoke-rc.d(8). Jan 2006 service(8)
All times are GMT -4. The time now is 09:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy