Monitor a long running process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Monitor a long running process
# 1  
Old 05-07-2010
Monitor a long running process

Gurus,

I am writing a shell script that will be used to automate cold backup of an Oracle Database. The database size is around 300G and will take around 5-6 hours to copy.

I have finished the script till the copy of the datafiles. Now, I am stuck at the point where I need to monitor the copy process.

I usually use while loop to monitor any long running process as below:

Code:
while true
do
if [[ $(ps -ef | grep <long running process id> | wc -l) -eq 0 ]];
then
<do something>
break
else
<do something>
fi

Now, my question is, is this the only way? Is someone using any other method to monitor a long running process?Smilie

Do share your thoughts.


Regards,

Praveen
# 2  
Old 05-07-2010
MySQL

If your copy successfull or not then let send mail..So we know about this
Let try this
Code:
#!/bin/bash
( time cp -fa /home/student/bin/.test /tmp/ & pid=$! ; wait $pid ) 2> oraclecopylog ; success=$?
myprocess=`echo ${0#./}`
 
while :; 
   do
      ps -ef | grep $myprocess | grep $pid
      status=$?
           if [ $status -ne 0 ] ; then
              mail -s "Oracle files copy is progressing.." ygemici@XX.com.tr < oraclecopylog
              sleep 3600 # control on every one hour  
                     else
              break
           fi
  done
if [ $success -eq 0 ] ; then
        mail -s "Oracle files copy is successfull" ygemici@XX.com.tr < oraclecopylog
                  else
        mail -s "There is a problem with copy oracle files" ygemici@XX.com.tr < oraclecopylog
fi


Last edited by ygemici; 05-07-2010 at 09:01 AM..
# 3  
Old 05-07-2010
Quote:
Originally Posted by sunpraveen
I usually use while loop to monitor any long running process as below:

Code:
while true
do
if [[ $(ps -ef | grep <long running process id> | wc -l) -eq 0 ]];
then
<do something>
break
else
<do something>
fi

In my opinion, this is a very poor approach, as it is very vulnerable to false positives. What if a different command with a different pid contains an argument that matches the pid being grepped for? This code will not detect that the monitored process has died/exited. What's much worse, however, is that depending on the kernel process scheduler and the shell implementation, the grep command's pid argument itself could trigger a false positive when groveling through the ps output (and given the way this code is structured, to test for equality to zero as failure, this could be happening often ... silently).

I would (perhaps melodramatically Smilie) characterize this as an indiscriminate grepping of ps output. When dealing with multicolumn output whose values can collide (the arguments field, for example, can conceivably contain a username/pid/ppid/...), it is safer and easier to constrain the match to a specific column using AWK. And, if applicable, use ps' output options to limit output only to the fields that are necessary. If you are grepping for a pid, why not use a ps output format that only prints pid?

Instead of ...
Code:
if [[ $(ps -ef | grep <long running process id> | wc -l) -eq 0 ]];

I would suggest ...
Code:
if ! [ $(ps -o pid= -p <long running process id>) ]

Or, you could grep|wc the output of "ps -o pid= -p <long running process id>", if that feels more familiar Smilie

Regards,
Alister

Last edited by alister; 05-07-2010 at 12:36 PM..
# 4  
Old 05-11-2010
Alister and ygemici, Thanks a lot for your invaluable suggestions and tips.

My friend also suggested one solution.
  • Since the backup will take a minimum of 5-6 hours, instead of writing a script that has to sleep till the backup is complete, why not, schedule a cronjob that runs say 4 hours after the backup is kicked off.
  • This script can check if the backup is still running and exit if it is. If the backup is not running (i.e., it is finished), check whether the database is up or not and depending on that, start it up.
Seems like a workable solution instead of using the sleep command till the script complete.

What say?


Regards,

Praveen
# 5  
Old 05-11-2010
Quote:
Originally Posted by sunpraveen
Alister and ygemici, Thanks a lot for your invaluable suggestions and tips.

My friend also suggested one solution.
  • Since the backup will take a minimum of 5-6 hours, instead of writing a script that has to sleep till the backup is complete, why not, schedule a cronjob that runs say 4 hours after the backup is kicked off.
  • This script can check if the backup is still running and exit if it is. If the backup is not running (i.e., it is finished), check whether the database is up or not and depending on that, start it up.
Seems like a workable solution instead of using the sleep command till the script complete.

What say?


Regards,

Praveen
we know work times of oracle cp process or automatic in random times or related anything ?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command to get exact tomcat process I am running ignoring other java process

Team, I have multiple batchjobs running in VM, if I do ps -ef |grep java or tomcat I am getting multiple process list. How do I get my exact tomcat process running and that is unique? via shell script? (4 Replies)
Discussion started by: Ghanshyam Ratho
4 Replies

2. Shell Programming and Scripting

Killing the process if running for long time in script

I am running a script which will read the data from fail line by line and call the Java program by providing the arguments from the each line. The Java code is working fast for few records and for some records its getting hanged not providing response for morethan one hour. Currently am... (4 Replies)
Discussion started by: dineshaila
4 Replies

3. Shell Programming and Scripting

Check for long running process on AIX

I want to write a shellscript which determines if a particular process is long running than my specified threshold time. Eg: My process name is "prsd" and is expected to run for 15 mins and completes. If I set a threshold limit of 1 hour, and how we can the get output of the long running... (4 Replies)
Discussion started by: chandu123
4 Replies

4. UNIX for Dummies Questions & Answers

Long running sessions

Hi, How can i find out the average cpu utilization of a particular long-running process in UNIX? is there some command for this Thanks (3 Replies)
Discussion started by: arunmanas
3 Replies

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

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

7. UNIX for Advanced & Expert Users

How to check since when (for how long) a particular process is running ?

How do I check if a particular process is running from a certain date and time ? (2 Replies)
Discussion started by: hpuxlxboy
2 Replies

8. UNIX for Advanced & Expert Users

how to check how long the process has been running.

I have a requirement to check how long a process is running on unix system.If i use ps -ef i am getting the following message guest 2453638 1998920 0 16:16:05 - 0:00 dsapi_slave 9 8 0 but this is showing only time not the date.Can any one please advice me any script to find out how... (2 Replies)
Discussion started by: ukatru
2 Replies

9. Programming

How to monitor if a process is running

I would like to know if i can monitor if a process is running. I have one program wich is running all the time, called oliba, but sometimes it goes down, and I have to launch it again. Is there a way to monitor the pid of the program, and if the program goes down, to lauch it again? Can you give... (3 Replies)
Discussion started by: Pedro Tavares
3 Replies
Login or Register to Ask a Question