Prepending timestamps to output lines
<yambe:breadcrumb>Server_administration_tips_and_tricks|Server administration tips and tricks</yambe:breadcrumb>
Prepending timestamps to output lines
Sometimes one needs to know how much time a particular command or operation takes. One way of finding out time and CPU consumed by a task is to use time command. But time output will be shown at the end of the command. If command or operation has many intermediate output lines then one can use below described methods to get timestamp prepended to every output line. This way time by which program was able to generate a given output line can be seen.
annotate-output command
annotate-output command prepends current time in front of every output line. Example usage is:
annotate-output ls -l
Passing output to awk to add time-stamps
One can pass the output of command to awk to make it print time-stamps. Syntax for achieving this is:
<command> | awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; }'
<yambe:breadcrumb>Server_administration_tips_and_tricks|Server administration tips and tricks</yambe:breadcrumb>