The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ksh script using expr to calculate percentages wurzul Shell Programming and Scripting 6 05-01-2008 03:19 AM
calculate time itik AIX 2 02-14-2008 11:08 PM
how to calculate CPU time under HP-UX limame HP-UX 1 06-18-2007 02:28 PM
calculate the time differnce between two given timings Olti UNIX for Dummies Questions & Answers 1 01-05-2006 10:22 AM
Calculate Elapsed Time sysera Shell Programming and Scripting 5 06-16-2004 10:10 PM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-01-2001
sanjay92
Guest
 

Posts: n/a
Question Please Help ( Calculate time taken in a script)

Hello,
I want to know how to calculate time difference in unix shell script. Time command in unix will not solve my problem because it calculates total time taken by a script.

See the examle below.

example :-
#!/bin/ksh
# This is just example
# Start the timer
Shell commands ..
Shell commands .

# End of timer

# I want to know how much time taken between start the timer and end of timer.

Is there unix built in commands to do it easily.

Unix Guru's please suggest.
Thanks
Sanjay
Forum Sponsor
  #2  
Old 10-01-2001
sskb
Guest
 

Posts: n/a
Lightbulb

hi!
i think u can use the timex command. for more details just go thru the "man".
  #3  
Old 10-01-2001
sanjay92
Guest
 

Posts: n/a
Hello sskb,
Thanks for your response. I have to write the time or timex command for every shell command. What I want to do is take the difference of time between some line of commands in shell script.



See the example below.

example :-
#!/bin/ksh
# This is just example
# Start the timer
Shell commands ..
Shell commands .

# End of timer

Did you get what I am trying to say.

Sanjay
  #4  
Old 10-01-2001
sskb
Guest
 

Posts: n/a
Yes sanjay! i got ur point. but as far as i know there is no such built in command. but if you don't mind .. i would tell u what i would do in that case.

just get the date and time store it!
execute the stream of commands
then again get the date and time.

get the difference from that.

I hope u have better idea than this. if so, please let me know.

  #5  
Old 10-01-2001
sanjay92
Guest
 

Posts: n/a
Hello sskb,

Is there any straight forward method in Unix to subtract two time/date values. I know I can store date/time and in some temp variables but I have to write a programme to subtract these two values. I was looking for some Unix build in method for this. I know in unix there is something called difftime but I do not know how to use it in shell scripts.

Sanjay
  #6  
Old 10-01-2001
sanjay92
Guest
 

Posts: n/a
Can you tell me where the timex command is located. It is not in my path list. I can see man timex. I can see time command but unable to find out timex command in my system.
One question about time command.
# This command does not work in ksh but works in sh or bash.

$time -p echo sanjay

Why -p option of time command does not work in ksh.

Thanks
Sanjay
  #7  
Old 10-02-2001
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,664
I have timex in /usr/bin. ksh has a built-in "time". Specify /usr/bin/time to get the version you see on the man page.

ksh has a variable called SECONDS that is the seconds since midnight. You can save the value, do some stuff, then save the value again. Then just subtract the two values. It's very easy if it doesn't need to work across midnight...and even that isn't a terribly hard problem.

You can also do stuff like:
time ksh -c "command1 ; command2"
although you will want to subtract the overhead for ksh itself which you can get with something like:
time ksh -c ":"

This last idea is not very far from simply putting the two commands into a separate script and then running time on that script.
Google The UNIX and Linux Forums
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0