Difference between revisions of "Prepending timestamps to output lines"

From Notes_Wiki
(Created page with "<yambe:breadcrumb>Server_administration_tips_and_tricks|Server administration tips and tricks</yambe:breadcrumb> =Prepending timestamps to output lines= Sometimes one needs t...")
(No difference)

Revision as of 13:00, 24 March 2013

<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>