Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with Shell script - process running for more than 24 hrs.

Status
Not open for further replies.

AlStl

MIS
Oct 2, 2006
83
0
0
US
Guys,

I am a newbie to shell scripting.

I am dealing with an issue of a process being hung on a random basis for days. Is there a way to write a script that will send an email (with process or job details) if a process has been running for more than 24 hrs? I use cron to run different jobs. I would like to add this script to cron and run it x amount of times per day to scan the processes/jobs.

#!/bin/ksh

ps -ef | grep "app_id"

gives me all the processing running under app_id.

Any help will be highly appreciated.

Al
 
You could use the "elapsed" time info from ps.

ps -C rsyslogd -o etime

will show you the "elapsed" time from the process with the name "rsyslogd"

(Dont use ps together with "grep" - there is no need to do this and will often result in errors/failures - specially when there are kill-commands involved!)

OR: You could write a script which will create a 24 hour old file, like

touch -d yesterday /tmp/ref_file

and then get find to check if your process-id is running longer than that:

find /proc/<PID> -older /tmp/ref_file

and filter the output (or the error-code $?) in a script to get the result.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top