I'd like to use the time command in a bash script to calculate the elapsed time of the script and write that to a log file. I only need the real time, not the user and sys. Also need it in a decent format. e.g 00:00:00:00 (not like the standard output). I appreciate any advice.
You could use the
Notes: $((...)) can be used for basic arithmetic in bash – caution: do not put spaces before a minus - as this might be interpreted as a command-line option. See also: http://tldp.org/LDP/abs/html/arithexp.html EDIT: EDIT: Example for timing with milliseconds (actually nanoseconds but truncated to milliseconds here). Your version of
|
|||||||||||
|
From the man page for time: 1)There may be a shell built-in called time, avoid this by specifying /usr/bin/time 2)You can provide a format string and one of the format options is elapsed time - %E
Example:
|
|||||||||
|
Use the bash built in variable SECONDS. Each time you reference the variable it will return the elapsed time since the script invocation. Example:
Output: Start 0 Middle 10 End 20 |
||||
|
To use the Bash builtin
which will output the real time that looks like this:
or
The number specifies the precision and can range from 0 to 3 (the default). You can use:
to get output that looks like:
The |
|||
|
Not quite sure what you are asking, have you tried:
Edit: ok, so you know how to get the times out and you just want to change the format. It would help if you described what format you want, but here are some things to try:
This changes the output to one time per line in seconds with decimals. You only want the real time, not the other two so to get the number of seconds use:
|
|||||||||||
|