Operating System - HP-UX
1834130 Members
2999 Online
110064 Solutions
New Discussion

Time difference between two date command, How?

 
SOLVED
Go to solution
Sachin Patel
Honored Contributor

Time difference between two date command, How?

Hi All,
I have a script that runs for couple minutes to couple hours. I am trying to find out total time this script runs.
I have put a variable start_time=`date` at the begining of the script and end_time=`date` at the end. From this How can I get the total time.

Sachin
Is photography a hobby or another way to spend $
8 REPLIES 8
Sridhar Bhaskarla
Honored Contributor

Re: Time difference between two date command, How?

Sachin,

Did you think of the command "timex"?.

timex script

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
harry d brown jr
Honored Contributor

Re: Time difference between two date command, How?

Sri,

I was thinking the same thing!

live free or die
harry
Live Free or Die
S.K. Chan
Honored Contributor

Re: Time difference between two date command, How?

# man time
I've used this in the past ..
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Time difference between two date command, How?

The easiest method is to do this:
START=$(perl -e 'print time;')
do your stuff
FINISH=$(perl -e 'print time;')

These will return the time in epoch seconds; the elasped time is simply the difference between them.

If it ain't broke, I can fix that.
MANOJ SRIVASTAVA
Honored Contributor

Re: Time difference between two date command, How?

Hi Sachin

timex < command > will give you the total time in terms of real usr system taken by the command.

Manoj Srivastava
harry d brown jr
Honored Contributor

Re: Time difference between two date command, How?

Clay, I like the way you think! great answer!

live free or die
harry
Live Free or Die
Tom Danzig
Honored Contributor

Re: Time difference between two date command, How?

If you're using ksh or sh, at the end of the script put:

echo Total elasped time in seconds = $SECONDS

This is a built in variable that starts at zero when the script (or shell) starts. You can echo this at any point in the script to get elapsed time so far in the execution.
Sachin Patel
Honored Contributor

Re: Time difference between two date command, How?

Hi Clay,
I am using perl now. It is working fine. I have read your previous answer (Same command) regarding some time question but It didn't make me sense there.

Sachin
Is photography a hobby or another way to spend $