The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Average completion time calculation? Seawall UNIX for Dummies Questions & Answers 5 05-20-2008 07:13 AM
specifying an execution time VGR UNIX for Advanced & Expert Users 7 03-19-2008 05:32 AM
change time interval for /proc/loadavg calculation Rakesh Ranjan High Level Programming 2 05-12-2006 05:48 AM
last execution time cubs0729 UNIX for Dummies Questions & Answers 1 01-20-2006 08:45 PM
time calculation liux99 UNIX for Advanced & Expert Users 2 08-18-2005 11:33 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-24-2006
johnsonbryce johnsonbryce is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 7
script execution time calculation

I am writting a script in the ksh shell and am trying to find a way to report the total execution time of the script without requiring the user to specify the time function when executing the script.
Does anyone have any examples they have used. I have been setting up two date variables (one at the beginning $START_TIME and one at the end $END_TIME) and then do some calulation of the difference and display is to the user in minutes. No matter what I do it keeps giving me syntax errors.
any help
  #2 (permalink)  
Old 02-24-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
I use this in our build script.

Code:
        start_time=$(date +%s)
.
.
.
        finish_time=$(date +%s)
        echo "Time duration: $((finish_time - start_time)) secs."
Divide the above by 60 to get minutes.

Something like

min=$(( $((finish_time - start_time)) /60 ))

Last edited by vino; 02-24-2006 at 02:58 AM..
  #3 (permalink)  
Old 02-24-2006
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
date %s is a GNU extension so may not be available. You could use the ksh built-in variable $SECONDS instead.
  #4 (permalink)  
Old 02-24-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Quote:
Originally Posted by Ygor
date %s is a GNU extension so may not be available. You could use the ksh built-in variable $SECONDS instead.
Thanks Ygor for pointing that out.

Hmm... I should modify the script !
  #5 (permalink)  
Old 02-24-2006
vishallbansal vishallbansal is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 3
hi

Quote:
Originally Posted by vino
Thanks Ygor for pointing that out.

Hmm... I should modify the script !

hye dude the syntax for setting start_date is not working...
i am workin in bash...
i too tried out printing the time taken by a process
  #6 (permalink)  
Old 02-24-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Quote:
Originally Posted by vishallbansal
hye dude the syntax for setting start_date is not working...
i am workin in bash...
i too tried out printing the time taken by a process
What error are you encountering ?

Possibly you dont have GNU date. Post the results of

Code:
strings `which date` | grep '%s'
You should heed Ygor's suggestion.

Last edited by vino; 02-24-2006 at 04:29 AM..
  #7 (permalink)  
Old 02-24-2006
johnsonbryce johnsonbryce is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 7
$ strings `which date` | grep '%s'
$
Returns nothing
$ which date
/usr/bin/date
$

Here is the code I have been testing with:
#!/bin/ksh
start=$(date +%s)
time sleep 20
end=$(date +%s)
echo "Time: $((end - start)) secs."

Results: syntax error

changed to:
#!/bin/ksh
start=$SECONDS
time sleep 20
end=$SECONDS
echo "Time: $((end - start)) secs."

Results: This works!

My question now is, will it still work after hours of execution. How ofter does this value get reset?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:16 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0