Results 1 to 4 of 4
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 07-10-2008 #1Just Joined!
- Join Date
- Jul 2008
- Posts
- 3
Execution Time
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
- 07-10-2008 #2Linux Guru
- Join Date
- Nov 2004
- Posts
- 6,110
You could get that from the ps command. the execution time is column 10, $0 is the variable that holds the script name (at least in bash, I don't use ksh myself).
Code:ps aux |grep $0|awk '{print $10}'
- 07-10-2008 #3Linux User
- Join Date
- Jun 2007
- Posts
- 318
Why grep for the script when you have the PID. Here's a test script.
Code:#!/bin/ksh START_TIME="`ps -p $$ -o bsdtime=`" integer _ct=0 while [ $_ct -lt 1000000 ] do _ct=_ct+1 done END_TIME="`ps -p $$ -o bsdtime=`" echo $START_TIME $END_TIME
- 07-10-2008 #4Just Joined!
- Join Date
- Jul 2008
- Posts
- 3
that worked GREAT! Thanks.


Reply With Quote
