-
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
-
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}'
-
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
-
that worked GREAT! Thanks.