Operating System - HP-UX
1832906 Members
2648 Online
110048 Solutions
New Discussion

Re: Time difference script

 
SOLVED
Go to solution
Daryl_3
Occasional Contributor

Time difference script

I am trying to write a script that will take the current time and compair it to a previous time, to see if the current time is 2 hrs or more older than the previous time. Can this be done?
7 REPLIES 7
T G Manikandan
Honored Contributor

Re: Time difference script

Daryl_3
Occasional Contributor

Re: Time difference script

I did look at the link, and I don't think that it is what I need to help me. Since what I have to do is to check and see if the current time is two or more hours greater than the time stamps that I get from issueing a
ls -lt.

Thanks for your help,

Daryl
Clemens van Everdingen
Honored Contributor

Re: Time difference script

Hi,

Looks at this thread, might be of help.

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x155e7bb04b5cd611abdb0090277a778c,00.html

C.
The computer is a great invention, there are as many mistakes as ever, but they are nobody's fault !
Deepak Extross
Honored Contributor
Solution

Re: Time difference script

Daryl,
Try using epoch datetime. Something like this:

CURR=`/usr/contrib/bin/perl -e "print time"`
LAST=`ll...whatever logic u have here`
if [ $(($CURR-$LAST)) -gt 7200 ]
then
// greater then 2 hrs, do your stuff
fi
Peter Kloetgen
Esteemed Contributor

Re: Time difference script

Hi Daryl,

you can use the touch- command to make a reference- file with the desired timestamp:

touch desired_time_format file

After this, you can use find- command to compare the timestamps of reference file with your other files. For more information:

man touch
man find

Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
Daryl_3
Occasional Contributor

Re: Time difference script

Deepak Extross,

Thanks for the script information but do you know of a way to convert for eg 09:55 timestamp to epoch time?
Deepak Extross
Honored Contributor

Re: Time difference script

Hi Daryl,
Epoch time is the number of seconds elapsed since 01/01/1970 00:00:00 GMT.
Hence, one way to do this would be to note the current epoch time as well as hh:mm:ss time, calculate the number of seconds between hh:mm:ss and 09:55:00, and then simply subtract this figure from the current epoch time.
Hope this helps.