While we are on the subject of dates. Another date question


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers While we are on the subject of dates. Another date question
# 1  
Old 09-17-2001
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!
# 2  
Old 09-18-2001
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
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
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
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
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
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Splitting week start date and end date based on custom period start dates

Below are my custom period start and end dates based on a calender, these dates are placed in a file, for each period i need to split into three weeks for each period row, example is given below. Could you please help out to achieve solution through shell script.. File content: ... (2 Replies)
Discussion started by: nani2019
2 Replies

2. UNIX for Advanced & Expert Users

Date between 2 dates

Hi All, Can you help me in finding the business dates (Mon-Fri) between two date ranges.. (forget abt holidays in weekdays) searched and tried a lot but cant figure this. ISs there any special function availble in unix for this (5 Replies)
Discussion started by: Deena1984
5 Replies

3. Shell Programming and Scripting

ksh compare dates INSIDE a file (ie date A is > date B)

In KSH, I am pasting 2 almost identical files together and each one has a date and time on each line. I need to determine if the first instance of the date/time is greater than the 2nd instance of the date/time. If the first instance is greater, I just need to echo that line. I thought I would... (4 Replies)
Discussion started by: right_coaster
4 Replies

4. Shell Programming and Scripting

Need to capture dates between start date and end date Using perl.

Hi All, Want to get all dates and Julian week number for that date between the start date and end date. How can I achive this using perl? (To achive above functionality, I was connecting to the database from DB server. Need to execute the same script in application server, since databse... (6 Replies)
Discussion started by: Nagaraja Akkiva
6 Replies

5. Shell Programming and Scripting

Need to capture all dates between start date and End date.

Hi All, I enter Start date and end date as parameters. I need to capture dates between start date and end date. Please let me know if you have any idea the same. Thanks in advance. Nagaraja Akkivalli. (5 Replies)
Discussion started by: Nagaraja Akkiva
5 Replies

6. Shell Programming and Scripting

Using 'date' to list a range of dates

Hi guys, I have been trying to create a list of dates from a certain range, ie. range from 01011950 to 31122000 But when my below code reaches certain dates, it comes up with a; 'date: invalid date 'yyyy-mm-dd -d 1day' Sofar I have come up with the following, slow and ugly; ... (4 Replies)
Discussion started by: TAPE
4 Replies

7. Solaris

Date after 5 dates in YYYYMMDD format

Hi Experts, How to get date 5 days after current date in YYYYMMDD format? How do we compare date in YYYYMMDD format? Thanks (1 Reply)
Discussion started by: needyourhelp10
1 Replies

8. Shell Programming and Scripting

Generate quarter dates with begin date and end date

Hi All, I am trying to generate quarter dates with user giving input as begin date and end date. Example: Input by user: begin_date = "2009-01-01" end_date = 2010-04-30" required output: 2009-01-01 2009-03-31 09Q01 2009-04-01 2009-06-30 09Q02 . . till 2010-01-01 2010-03-31 10Q01 ... (9 Replies)
Discussion started by: sol_nov
9 Replies

9. Shell Programming and Scripting

Display the last five dates from the given date

Hi all, In Oracle we have got sysdate -1 to find the previous date. Is there any similar way to display date in unix shell scripting? Kindly help me to display the last five dates from the given date Thanks, Geetha (11 Replies)
Discussion started by: iamgeethuj
11 Replies

10. UNIX for Dummies Questions & Answers

using 'date' to get previous days' dates

I am familiar with using the 'date' command to get the current date but I have a situation where I need to get the previous day's date as well as the date two days prior. Theoretically I could use 'expr' to compute these values but I need it to work in instances where the previous month's dates... (2 Replies)
Discussion started by: slant-40
2 Replies
Login or Register to Ask a Question