Operating System - HP-UX
1837187 Members
2423 Online
110114 Solutions
New Discussion

Re: time it takes to complete script

 
SOLVED
Go to solution
Ratzie
Super Advisor

time it takes to complete script

I need to figure out how long it takes to complete a process.

Right now in my script I have...
echo "Such and such started at `date`"

I would also like it to at the end state
echo "It took ?? minutes to complete this process"

One more thing, I would also like to add...
The size of the file is ?? MB or GB. How do you convert an ls -l on a file?
Is ls -l in HP 11.00 showing it in kb, then I would times by 1024? for mb?
4 REPLIES 4
Sridhar Bhaskarla
Honored Contributor
Solution

Re: time it takes to complete script

Hi,

If you want the time to be calculated within the script, you can use the built-in variable "SECONDS".

start=$SECONDS
your_script..
..
..
end=$SECONDS

(( TIME = ( $end - $seconds ) / 60 ))

echo "Time it took is $TIME minutes approximately"


Actually the size you get in ls -l is in bytes. You will need to devide it by 1048576 (1024*1024) to get it in MB.

SIZE=$(ls -al file|awk '{print $5/1048576}')
echo "size is $SIZE

TO calculate the size of a file, I would do the following

SIZE=$(du -sk file|awk '{print $1/1024}')
echo "Size of the file is $SIZE MB"

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sridhar Bhaskarla
Honored Contributor

Re: time it takes to complete script

Hi (again),

I should have added. From externally you can use the command timex while running the script to get the total time it took.

timex your_script

real 0.02
user 0.01
sys 0.01

YOu should see something like the above. real is the real time it took. user is the time cpu spent to run the program in user mode and sys is the time cpu spent to run in kernel mode.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sanjay Kumar Suri
Honored Contributor

Re: time it takes to complete script

Hello

#ls -l show the size in bytes.

#du -ak can show the figures in Kbytes.

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Steve Lewis
Honored Contributor

Re: time it takes to complete script

This script will convert an ll into Kb/Mb/Gb as appropriate:

ll "$*" | awk '
function sv(val)
{
pv=sprintf("%3.3fKb",val/1024.0);
if (val>=1048576.0) pv=sprintf("%3.3fMb",val/1048576.0);
if (val>=1073741824.0) pv=sprintf("%3.3fGb",val/1073741824.0);
return pv;
}
{
if($1~"d.")
printf("%10s %-5d %9s %9s %3s %-2s %5s %s\n",$1,$2,$3,$4,$6,$7,$8,$9);
else printf("%10s %-5d %9s %9s %10s %3s %-2s %5s %s\n",$1,$2,$3,$4,sv($5),$6,$7,$8,$9);
}'