KSH - Execution Time

Hello,

I am on solaris 9 (KSH). I need to get the execution time of my script. I can't use the time command as I have to send by mail the result in a human readable way.

So I am looking for a code to add to my script.

The output result would be :

Execution time : hours-minutes-seconds  

like this : 01h-23mns-15s if possible

Thanks for your help.

Hi.

I am not sure which execution time you mean, so I'll assume wall-clock time. I use command sleep in this demonstration. Here's an example using GNU time:

#!/usr/bin/env ksh

# @(#) s2	Demonstrate time in ksh.

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && . $C time sleep
pe

SNOOZE=${1-10}

/usr/bin/time -f '\n Elapsed [hours:]minutes:seconds %E' sleep $SNOOZE

exit 0

producing:

% ./s2

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
ksh 93s+
GNU time 1.7
sleep (GNU coreutils) 6.10


 Elapsed [hours:]minutes:seconds 0:10.00

Best wishes ... cheers, drl