The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Compare dates in a field and print the latest date row cvkishore Shell Programming and Scripting 1 08-04-2007 04:58 AM
Date question 12yearold Shell Programming and Scripting 1 07-25-2006 10:46 PM
Date question dsimpg1 AIX 1 12-02-2005 10:40 AM
date question rdeschene3 Shell Programming and Scripting 3 06-01-2005 04:46 PM
date question ankurgupta UNIX for Advanced & Expert Users 3 03-13-2002 10:11 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 09-17-2001
MizzGail's Avatar
Registered User
 

Join Date: Sep 2001
Location: Syracuse, NY
Posts: 158
Question While we are on the subject of dates. Another date question

This goes deeper into the date thing. I want to be able to check the date and time stamp in or on a file to see what the time span is.

We have a job that runs several times an hour - kicked off through cron based on a trigger file. We want to keep track of each run and check the time between runs for reasonbleness because the job can hang and not notify anyone. Right now we have someone watching the job during peak hours and manually determining that it has been in the run state too long. I would like to automate the reasonbleness check for automated notifies.
(the hanging is out of our control so we need to automate the monitor process)
We put a time stamp in a log of when the job starts, so we already have that peice. What I don't know how to do is manipulate date and time down to minutes.

THANKS!
Forum Sponsor
  #2  
Old 09-17-2001
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Check the man page for the `date` command.
Most of the time, it will follow a format similar to the following:
date +%H:%M:%S - This will give a format of the following:
07:09:59

But the most help you'll probably get is:
man date
  #3  
Old 09-18-2001
MizzGail's Avatar
Registered User
 

Join Date: Sep 2001
Location: Syracuse, NY
Posts: 158
thank you , I guess I should have been more specific. I know how to get the date and time.
I need to obtain the time difference between the start times of my jobs.
ie. the job kicks off at 8:30:00 then again at 8:47:00 I need to calculate the difference between these two times. then I can do a reasonbility check for the time span - if the time span is greater than 15mins, I want to send a notify to a pager. I know how to send the notify, what I am looking for is how to determine the time span / difference.

thanks
  #4  
Old 09-18-2001
flim flam flamma jamma
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
why not toss another date time stamp w/ something signifiing then end of the run. This will alow you to do 2 things.

1) let you know how long it took to do the job in the first place.
2) let you know the time between jobs.

ie:

==== Job Begins date-time-stamp ====
what ever you do to your files
......
==== Job EOF date-time-stamp ====
  #5  
Old 09-18-2001
MizzGail's Avatar
Registered User
 

Join Date: Sep 2001
Location: Syracuse, NY
Posts: 158
I have that information.
I am not looking for logical approaches....
I am looking for the technical way of how do I subtract the start time from the end time to get the time span?

I have the time 08:30:00 how do I write script code to subtract it from 08:47:00 ???????????

I can awk out the hour and minutes and seconds and work that way then put it all back together, but I want to know if anyone has an easier way to calculate elapsed time.
  #6  
Old 09-18-2001
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,613
Well, you can take the hour, multiply by 60, then add the minutes to get minutes after midnight. But how on earth does comparing the start times of two jobs help you know when one is hung? And why worry about the start times of jobs started via cron anyway?

If want to detect a job that runs longer than 15 minutes, just use a shell wrapper:
Code:
#!/usr/bin/ksh
job_that_might_hang &
pid=$!
sleep 900
if kill -0 $pid 2>/dev/null ; then
   echo background job is still running
else
   echo background job finished
fi
exit 0
  #7  
Old 09-18-2001
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
do something like this:

Code:
#start of job
echo $(date +%H%M%S) >> /some/place/log
#
# job here
#
echo $(date +%H%M%S) >> /some/place/log
#now, to compare
date_1=$(tail -2 /some/place/log | head -1)
date_2=$(tail -1 /some/place/log)
check_time=$(expr ${date_2} - ${date_1})
if [ "$check_time" -gt "1500" ] ; then
     echo "Uh oh!" | mail mizzgail -s "your process got stuck"
fi
This isn't very proactive, but it would be fairly easy to construct a script that could poll, comparing the current time (in a similar fasion as above) to the start time. Also, instead of mail, you could send a message directly to a users console... etc...

Hope that helps.
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:00 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0