Shell Runtime Statistics

Hi,

I am trying to capture runtime stats of a shell script (c shell). Are there system variables to call? Or should I create a date variable at the start of the script and at the end of the script? I am trying to capture the time if the script stops or ends with error.

Please help.

Thanks!

You could try the shell builtin time. Its output may not be 100% what you want but could perhaps be manipulated into being it.

Since it's a shell builtin though you'll have to be clever about capturing it.

# doesn't work
$ time echo 2> logfile

real    0m0.000s
user    0m0.000s
sys     0m0.000s
# Works
$ ( time something ) 2> logfile
$

How would I put this in a shell script?

Should I set as variable at the beginnning of the script and call at the end? Or should I call it at the end of the script?

Can you explain the 'something' part - so I pass a variable?

Thanks

The 'something' is the command you wish to get statistics on. It has to be an executable or script file. You can't get statistics on part of a shell script AFAIK.

Thanks for the tips,

I am now trying to capture the elapsed time into a variable in (C Shell). I would like to 'echo' the start time, end time and time elapsed - along with other variables and commands.

Please advise.