It took me a little time to find a way to get the amount of time it took for a shell script to execute. Every time I looked for it on the web I would get all kinds of other wild stuff. Well I had come across a way to time PHP execution times and after reading that figured how different could it be?
Using basic principals the following was derived. It takes a start time and an end time, gets the difference and then formats that difference using the date command. Thats right, date will format a string for you based on certain input data.
To start the timing use:
To end the timing use the following. Of course you will want this as close to the end as you can get it if you use it inside the script. So far I have only used it in my backup-usb script and it ends just before the info is spit out on screen at the very end.
Then calculate the difference and then format it as needed:
TTIME="$(expr $FINISH - $BEGIN)" YEAR="$(date +%Y-%m-%d)" RTIME=`date -d "$YEAR $TTIME sec" +"%H:%M:%S"
The variable RTIME is assigned the run time, hence the name. Do with it what you please!