Login or Register to Ask a Question and Join Our Community


Process monitoring for a fixed time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Process monitoring for a fixed time
# 1  
Old 05-26-2014
Process monitoring for a fixed time

Hi Gurus,

I have a scenario where i need to monitor for a process which starts at a particular time. I need to check if the process has started at the specified time and keep checking this for 5 minutes only and then want to alert me.

Code:
ps -ef | grep -i process.sh | grep -v grep > path/process.txt
if [-s process.txt]
mail "Process started on time" abc@xyz.com
else
mail "Process did not start on time" abc@xyz.com
fi

The code above could be used for a particular time only. But we need the above to wait for every 5 seconds for 5 minutes continuously monitoring the process before executing it.

Thanks
Jay

Last edited by Don Cragun; 05-26-2014 at 03:22 AM.. Reason: Fix tags.
# 2  
Old 05-26-2014
Code:
for i in $(seq 1 60)
do
  sleep 5
  if [[ $(ps -eaf | grep [p]rocess.sh) ]]; then
    echo "process is running"
  else
    echo "process completed"
  fi
done

# 3  
Old 05-26-2014
Hi Srini,

Thanks for the reply.

Sorry i am not able to understand the script as i am not familiar with seq.

I dont see the value of i being used anywhere in the script. I want the script to monitor the process for 5 minutes and for every 5 seconds in that 5 minutes.
# 4  
Old 05-26-2014
I don't understand the requirements well enough to give you a complete answer. But here's a sample of how you can use "pkill" (if you system has it) to determine if a process is running or not. I think it's simpler and easier to understand than a pipeline of ps/grep.

Code:
RUNCHECK() { pkill -0 "$1" 2>/dev/null && echo "$1 is running" || echo "$1 NOT running"; }

Sending a "0" signal doesn't actually send any signal to the process. So you can't unintentionally interrupt it. It's just a simple way to find out if the process with the given pattern is running.
# 5  
Old 05-26-2014
Quote:
Originally Posted by jayadanabalan
Sorry i am not able to understand the script as i am not familiar with seq.
"seq" just produces a row of successive values, in this case "1 2 3 4 ..." up to 60. As the script is sleeping for 5 seconds running this 60 times will provide a running time of 5 minutes (60x5 seconds).

I hope this helps.

bakunin
# 6  
Old 05-26-2014
seq is sequence.
I am waiting for 5 seconds, 60 times..which becomes every 5 seconds for 5 mins
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. What is on Your Mind?

Fixed Password Bug in Registration Process

Today I found out that many new user registrations were having trouble logging in. I spend about three hours debugging this, and I think I fixed the problem. If anyone registers and has trouble logging in please contact me on Live Chat. Thanks. (1 Reply)
Discussion started by: Neo
1 Replies

2. Shell Programming and Scripting

Monitoring processes in parallel and process log file after process exits

I am writing a script to kick off a process to gather logs on multiple nodes in parallel using "&". These processes create individual log files. Which I would like to filter and convert in CSV format after they are complete. I am facing following issues: 1. Monitor all Processes parallelly.... (5 Replies)
Discussion started by: shunya
5 Replies

3. War Stories

One time I fixed an LCD monitor with a folded piece of paper

Some of the colors weren't working on the Monitor. I found pressing around the plastic border of the screen brought them back. I opened the monitor casing and used the folded paper to put pressure against the LCD panel and housing. Wah Lah. More of a bend than a hack I guess. (2 Replies)
Discussion started by: herot
2 Replies

4. Shell Programming and Scripting

How to calculate time difference between start and end time of a process!

Hello All, I have a problem calculating the time difference between start and end timings...! the timings are given by 24hr format.. Start Date : 08/05/10 12:55 End Date : 08/09/10 06:50 above values are in mm/dd/yy hh:mm format. Now the thing is, 7th(08/07/10) and... (16 Replies)
Discussion started by: smarty86
16 Replies

5. Shell Programming and Scripting

Help on Process Monitoring Script

Hi All, I have a Java application running in the background which process looks like this. java -DMyService=Y -DWorkingDir And I have a monitoring script which looks like this; count_service=`ps -aef | grep MyService | wc -l` if ; then echo "Service_Stopped on `date`" >>... (6 Replies)
Discussion started by: swmk
6 Replies

6. Shell Programming and Scripting

System time comparison to fixed defined time

I have a requirement of checking the current system time and performing certain actions in a shell script. example: if the current system time is greater than 1400 hrs, then perform step 1,2,3 if the current system time is greater than 1000 hrs, then perform step 1,2 if the current system time... (2 Replies)
Discussion started by: zainravi
2 Replies

7. Shell Programming and Scripting

script to run repeatedly after a fixed interval of time

Hi , I am working on the following script . I want this script to run and scan the log file repeatedly after 3 hours. This script will run & scan just for the current date logs and after every 3 hours. Kindly advice what to add in this script for this purpose. #!/bin/sh diff common.log... (3 Replies)
Discussion started by: himvat
3 Replies

8. Shell Programming and Scripting

process monitoring

hi all, i would like to write the shell script to monitoring the processing, but if i passing the parameter the number of process is incorrect how to slove it? many thx got the correct number of process as following script: ===========================================================... (3 Replies)
Discussion started by: eric_wong_ch
3 Replies

9. Shell Programming and Scripting

Process Monitoring Script Help

I have a shell script which runs from 7AM to 3AM every day. The script performs certain monitoring functions and if it has a problem it may need to email someone about it. The problem is that the notification process was never modified to handle running past midnight (from 23:59:59 till 3AM). ... (0 Replies)
Discussion started by: rdc69
0 Replies
Login or Register to Ask a Question

Featured Tech Videos