Shell Script Statistics

Hi All,

I am writing a UNIX shell script for the Database Operations and wanted to take the statistics i.e. How much time my script has taken to complete the operation.

I wanted to apply the logic say: In the beginning of the script I will store the value of current date and time in some variable and then finally I will take the difference of that datetime variable from the current date and time.

I am very new to shell scripting. Can some one help me to put this logic into the shell script code.

Let me know if any new logic will hold good for my requirments.

use time command

 
$time yourscript.sh
1 Like
$ time ./script.sh
or
$ time sh script.sh
1 Like

I want to write this statistics into a log file (writing logs through the same script).... When I used the above suggestions in my script it says can't execute the script.sh :frowning:

#! /bin/bash

start=`date +%s%N`

echo "hello"
sleep 1
echo "world"
sleep 1

end=`date +%s%N`
dif=$(($end - $start))

echo "Execution time in nanoseconds: $dif"

You can do an appropriate conversion to seconds using the bench calculator.

1 Like

It Worked for me....

Thanks Again
Ambar Agrawal