Operating System - HP-UX
1834461 Members
2936 Online
110067 Solutions
New Discussion

Re: Are there any tools or scripts available that will take two timestamps and return elapsed time?

 
SOLVED
Go to solution
Jack C. Mahaffey
Super Advisor

Are there any tools or scripts available that will take two timestamps and return elapsed time?

I'm want to be able to generate an elapsed time value by passing two timestamps. Has anyone seen anything that can do this.

Example:
# elapsed 20020301 12:22:00 20020302 12:23:00
Elapsed time: 24 Hour(s} 1 minute(s) 0 Seconds(0)

# elapsed 12:23:00 12:44:01
Elapsed time: 1 Minute(s) 1 Second(s)

I could do this on Tandem and would like to do the same on HP-UX. Using the time command requires it being part of the script.

Thanks... jack...
17 REPLIES 17
Patrick Wallek
Honored Contributor

Re: Are there any tools or scripts available that will take two timestamps and return elapsed time?

Hey Clay,

Is this another job for your caljd.sh script? :)
Ian Dennison_1
Honored Contributor

Re: Are there any tools or scripts available that will take two timestamps and return elapsed time?

2 options,.....

timex - the command returns CPU (User and system) and real time for command that is specified.

ctime (a C function) - write a C program to return the ctime value for current time (number of seconds since the epoch), and use this in your calculations. I myself have written this C program before, so it can't be that hard. Unfortunately I wrote it for another company so had to leave it behind.

Share and Enjoy! Ian
Building a dumber user
H.Merijn Brand (procura
Honored Contributor

Re: Are there any tools or scripts available that will take two timestamps and return elapsed time?

just write a thin little wrapper round 'perl -MDate-Calc'

from man Date::Calc

Delta_DHMS
($Dd,$Dh,$Dm,$Ds) =
Delta_DHMS($year1,$month1,$day1, $hour1,$min1,$sec1,
$year2,$month2,$day2, $hour2,$min2,$sec2);
Enjoy, Have FUN! H.Merijn
Jack C. Mahaffey
Super Advisor

Re: Are there any tools or scripts available that will take two timestamps and return elapsed time?

I really don't want to write a C or perl program. I was hoping something was already out there.

Don't have C or perl background.

jack...
H.Merijn Brand (procura
Honored Contributor

Re: Are there any tools or scripts available that will take two timestamps and return elapsed time?

Your example is a bit misleading, but I could not resist the temptation. Here's the script (attached)

a5:/pro/3gl/CPAN 119 > elapsed.pl 12:09:12 18:04:05
Elapsed time: 5 hour(s) 54 minute(s) 53 second(s)
a5:/pro/3gl/CPAN 120 > elapsed.pl 12:09:12 18:04:15
Elapsed time: 5 hour(s) 55 minute(s) 3 second(s)
a5:/pro/3gl/CPAN 121 > elapsed.pl 20020301 12:22:00 20020302 12:23:00
Elapsed time: 1 day(s) 0 hour(s) 1 minute(s) 0 second(s)
a5:/pro/3gl/CPAN 122 > elapsed.pl 12:23:00 12:44:01
Elapsed time: 21 minute(s) 1 second(s)
a5:/pro/3gl/CPAN 123 >
Enjoy, Have FUN! H.Merijn
Jack C. Mahaffey
Super Advisor

Re: Are there any tools or scripts available that will take two timestamps and return elapsed time?

We're getting real close. I got the following by running the script:

[8133]root@chldevh:/usr/local/bin # elapsed.pl 12:12:22 12:14:22
"use" may clash with future reserved word at /usr/local/bin/elapsed.pl line 4.
syntax error in file /usr/local/bin/elapsed.pl at line 4, next 2 tokens "use strict"
"use" may clash with future reserved word at /usr/local/bin/elapsed.pl line 6.
syntax error in file /usr/local/bin/elapsed.pl at line 8, next 2 tokens "\usage ("
Execution of /usr/local/bin/elapsed.pl aborted due to compilation errors.
[8134]root@chldevh:/usr/local/bin #


jack...
H.Merijn Brand (procura
Honored Contributor

Re: Are there any tools or scripts available that will take two timestamps and return elapsed time?

Ahhhhhrggggggg. Not perl5.005_03 or up.

Do you have the September applications nearby? Install newer perl please. (what's the version you use? 4.036?)

(And asign points to the answers, look at http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x316efd3f91d3d5118ff40090279cd0f9,00.html)
Enjoy, Have FUN! H.Merijn
Ralph Grothe
Honored Contributor

Re: Are there any tools or scripts available that will take two timestamps and return elapsed time?

"use" may clash with future reserved word
...
Ha, ha, this is really funny, I guess you were invoking a Perl 4 interpreter,
send your complaint to HP...

What is the output of

perl -v
perl -e 'print "@INC\n"'

Have you installed the module Date::Calc from CPAN.
(even if, this will most likely require a Perl 5.X)

Btw, Date::Calc wouldn't even be necessary.
The use of localtime() and timelocal() from Time::Local which are both standard Perl functions/modules would suffice for Epoch seconds calculations.

But anyway, you would only be able to do integer seconds timings.

If you require milli or micro seconds you could install and use Time::HiRes from CPAN, but let procura explain to you how to install and use those modules ;-)
Madness, thy name is system administration
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Are there any tools or scripts available that will take two timestamps and return elapsed time?

Okay Jack:

I spent a few minutes doing a non Perl version although the Perl version (if you download and install the Date::Calc module from CPAN) will work nicely.

And yes Patrick, I do call the caljd.sh utility.

I attach this in two parts:

By the way, this version only does hrs, mins, and seconds so that extra days show up as hous but that seemed to follow your example.

Here is elapsed.sh.

Regards, Clay
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Are there any tools or scripts available that will take two timestamps and return elapsed time?

Hi again:

Here is my universal date hammer (now where's your nail?) caljd.sh


Regards, Clay
If it ain't broke, I can fix that.
Jack C. Mahaffey
Super Advisor

Re: Are there any tools or scripts available that will take two timestamps and return elapsed time?

Works great!!!! I love it.... :)


Thanks to all and thanks for such quick responses.


Jack...
Jack C. Mahaffey
Super Advisor

Re: Are there any tools or scripts available that will take two timestamps and return elapsed time?

And yes, I am runnung perl 4.0. I'll look into getting 5

perl -e "print '@INC\n'" returns
@INC

jack...
Jack C. Mahaffey
Super Advisor

Re: Are there any tools or scripts available that will take two timestamps and return elapsed time?

I got the 5.1.6 version of perl, installed it and now need to find the CPAN module Date::Calc. Haven't been able to find it yet, however.


jack...
Patrick Wallek
Honored Contributor

Re: Are there any tools or scripts available that will take two timestamps and return elapsed time?

Ralph Grothe
Honored Contributor

Re: Are there any tools or scripts available that will take two timestamps and return elapsed time?

Jack, just a few hints regarding Perl and modules (trying to increase the Perl user base ;-)
You can get all the good modules from the CPAN (comprehensive perl archive network).
It is an invaluable source of combined Perl programmers' efforts, and can save you many, many hours.
Patrick has pointed you already in the right direction.
Here especially you can get Date::Calc
http://www.cpan.org/modules/by-module/Date/

You can download every module and install it almost always using the same mantra:
1) unzip and untar tarball
2) cd to new directory
3) *read* the README to find out prerequisites
4) issue "perl Makefile.PL"
this will create a Makefile using the ExtUtils::MakeMaker module
5) make
6) make test
7) make isntall
(this step should be done as root to have the module installed in the sit_lib subdir under the perl tree)

*But* it can save you a lot of repetitive, manual downloading, making, installing if you use the module CPAN by Andreas K??nig

You first have to do a configuration run.
issue

perl -MCPAN -e shell

will get you ask you many questions which you interactively will have to answer.
If you are sitting behind a proxy/firewall like me, things can be a bit tricky (but CPAN module will ask you for that).
It may also help to download and install wget first and set the passive flag when you are behind a proxy.

The after all this unique work you simply install whole bundles like this
e.g.

cpan> install Bundle::LWP

and watch in admiration what the CPAN module is doing.

But first of all get and install a decent Perl version (e.g. 5.6.1)!!!
Madness, thy name is system administration
H.Merijn Brand (procura
Honored Contributor

Re: Are there any tools or scripts available that will take two timestamps and return elapsed time?

He /did/ get a decent perl, but just typoed it as 5.1.6 (which has never even existed) instead of 5.6.1
Enjoy, Have FUN! H.Merijn
Jack C. Mahaffey
Super Advisor

Re: Are there any tools or scripts available that will take two timestamps and return elapsed time?

Thanks for the info on perl. I've been having problems with the compile. gcc compiler has been previously compiled. Will get back later with more info....

jack...