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...")
 
m
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<yambe:breadcrumb>Server_administration_tips_and_tricks|Server administration tips and tricks</yambe:breadcrumb>
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[Server administration tips and tricks]] > [[Prepending timestamps to output lines]]
=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.
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.
Line 21: Line 20:




<yambe:breadcrumb>Server_administration_tips_and_tricks|Server administration tips and tricks</yambe:breadcrumb>
 
Steps learned from http://stackoverflow.com/questions/21564/is-there-a-unix-utility-to-prepend-timestamps-to-lines-of-text
 
 
 
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[Server administration tips and tricks]] > [[Prepending timestamps to output lines]]

Latest revision as of 15:56, 22 July 2022

Home > CentOS > CentOS 6.x > Server administration tips and tricks > 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; }'


Steps learned from http://stackoverflow.com/questions/21564/is-there-a-unix-utility-to-prepend-timestamps-to-lines-of-text


Home > CentOS > CentOS 6.x > Server administration tips and tricks > Prepending timestamps to output lines