Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timer 3

Status
Not open for further replies.

Michael42

Programmer
Oct 8, 2001
1,454
US
Hello,

For a Bourne shell script, can anyone pelase share the code snippets required display how long a script took to run?

I am thinking there needs to be at minimum two variables: TIMER_START and TIMER_END, but I am not sure how to best set the values and calculate the elapse time.

Thanks,

Michael42
 
Guys,

In a Bourne script could you please elaborate on how to create a timer, or output at the end of the script the elapse time it took to run it.

I don't quite grab the mechanics of how to achieving this one.

Thanks,

Michael42
 
Michael42 said:
...or output at the end of the script the elapse time it took to run it.

Like Trojan said...
Code:
time script.sh
This will run your script, then after it's done, it will display three times, the elapsed time, the user CPU time, and the system CPU time it took to run the script. It looks like this...
Code:
real    1m2.46s
user    0m1.25s
sys     0m6.75s
Is this what you're looking for?
 
A starting point:
Code:
s=`eval 'date "+expr \( 3600 \* %H \) + \( 60 \* %M \) + %S"'`
start=`eval $s`

# your script here

s=`eval 'date "+expr \( 3600 \* %H \) + \( 60 \* %M \) + %S"'`
end=`eval $s`
echo "Elapsed time = `expr $end - $start` seconds"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
You guys are geniuses as usual! :)

PHV, that was what I was looking for. Perfect.

Sam, Trojan: that time command is great. I never knew it existed.


Guys, thanks for posting,

Michael42
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top