Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-03-2012
Registered User
 
Join Date: Jun 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Total time taken

Hi Friend,
Need your help.
I have a file which has information of start time and End time . I need to find how much time takes to complete the job . how can I do it in unix command .

Example of Log file :


Code:
 Start Loading                     ---Thu Aug  2 17:14:09 EDT 2012
 Load completed   successfully---Fri Aug  3 09:00:44 EDT 2012

Moderator's Comments:
Code tags for code, please.

Last edited by Corona688; 08-03-2012 at 12:48 PM..
Sponsored Links
    #2  
Old 08-03-2012
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,371
Thanks: 490
Thanked 2,534 Times in 2,417 Posts
This may be simple on some systems and extremely difficult in others. What's your OS and shell? uname -a if you don't know.

If you have Linux, converting dates into timestamps is straightforward:


Code:
$ date +%s -d "Thu Aug  2 17:14:09 EDT 2012"

1343942049

$

...and getting the difference between two times becomes a matter of simple arithmetic.

Last edited by Corona688; 08-03-2012 at 12:54 PM..
Sponsored Links
    #3  
Old 08-07-2012
Registered User
 
Join Date: Jun 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
OS is AIX .
    #4  
Old 08-10-2012
Registered User
 
Join Date: Jun 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
We changed the code and put the following logic

Code:
START=$SECONDS
END=$SECONDS
echo elapsed time is $((END-START)) seconds

Can any one help how to convert this seconds in HH MM SS format
Sponsored Links
    #5  
Old 08-10-2012
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,371
Thanks: 490
Thanked 2,534 Times in 2,417 Posts
That comes down to math.


Code:
SS=$(( (END-START) % 60 ))
MM=$(( ((END-START) / 60) % 60 ))
HH=$(( ((END-START)/(60*60))%24 ))

Sponsored Links
    #6  
Old 08-11-2012
Registered User
 
Join Date: Jul 2010
Posts: 26
Thanks: 5
Thanked 2 Times in 2 Posts
Not sure but does AIX have the 'time' command? If so, preface your command with the time command

Code:
time <your command>

This will provide the system time, the user time and the total time.
Sponsored Links
Closed Thread

Tags
total time taken

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Total Time j_panky Shell Programming and Scripting 21 06-01-2011 06:59 AM
How to get total time using awk ashimada Shell Programming and Scripting 8 07-22-2010 10:47 PM
Calculate total space, total used space and total free space in filesystem names matching keyword bigben1220 Shell Programming and Scripting 4 11-25-2009 10:37 AM
grep running total/ final total across multiple files MrAd UNIX for Dummies Questions & Answers 5 05-08-2007 01:03 PM



All times are GMT -4. The time now is 08:31 AM.