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!

Script to run for 3 hours 1

Status
Not open for further replies.

JBaileys

Technical User
Jun 23, 2003
244
0
0
US

Is there a way to look to see if a process is running for more than 3 hours. If it is running more than 3 hours, it should echo a simple failure message.

#identify process to kill

STARTDATE=`date -d +%s`
# Timelimit in seconds
TIMELIMIT = 10800
CDATE=`date -d +%s`
DIFF = CDATE - STARTDATE

while (proc_id exists)
if [[DIFF ge timelimit]]
# timelimit exceeded
kill proccess
fi
CDATE=`date -d +%s`
DIFF = CDATE - STARTDATE
end while
 
Yes. Please see man ps for the various options of the 'ps' command. Also you will need to decide whether the 3 hours is 'elapse time' or 'cpu usage time'. There are slight variations in output depending on the version of *nix being used.

I hope that helps.

Mike
 

The 3 hours is elapsed time (not cpu time).

Thanks,

jb
 
Ok. Then you need to try something like:
ps -ef -o user,pid,stime | grep <process> | grep -v

(which works on Solaris & Tru64) to get the output that you need to test in your script.

You should consider what to do with a process that started yesterday, and how to compare the start time with your 'STARTDATE' format, and what you want to do when you've found it/them (echo a simple failure message OR kill process).

I hope that helps.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top