[ale] line timestamp command

Doug Hall doughalldev at gmail.com
Tue Nov 12 15:20:04 EST 2013


#!/usr/bin/env ruby -i
# Print all the lines from STDIN, prepended with the current time
ARGF.each_line do |line|
  puts Time.now.to_s + ":" + line
end

-------


Assuming you have ruby installed, create a file with the above contents. I
called it in_timestamped.rb. Change it to an an executable :

chmod +x in_timestamped.rb

Then, make sure it's installed into a directory in your $PATH.

On Tue, Nov 12, 2013 at 1:58 PM, Ed Cashin <ecashin at noserose.net> wrote:

> I do happen to know of one, but it's by Dan J. Bernstein.  That sometimes
> means it's of uncommonly high quality and careful design but low user
> convenience.
>
> Usually the resolution is to do everything the way DJB thinks things
> should be done.  Then it's convenient and reliable.  But it requires the
> user to adjust behavior and/or expectations.  In this case, tai64n does
> what you ask for, but the timestamp is not probably anything you'd want to
> read.  So tai64nlocal converts it.  Weird, but not carelessly designed.
>
> http://cr.yp.to/daemontools/tai64n.html
> http://cr.yp.to/daemontools/tai64nlocal.html
>
>
>
> On Tue, Nov 12, 2013 at 1:34 PM, Scott Plante <splante at insightsys.com>wrote:
>
>> Does anyone happen to know of a command line tool that will read lines
>> from standard input and write them to std out, pre-pending a timestamp? I
>> have a process that emits messages to std out periodically as it processes
>> and I'd like to write that to a log file, but with a time at the start of
>> the line. I could do it with a script but a nice little command would be
>> better, if it exists.
>>
>> I'm looking for something that would perform the function of this script,
>> maybe with an option for format:
>>
>> while read line;
>> do
>>   echo $(date +"%D %T") "$line";
>> done
>>
>> Scott
>>
>>
>> _______________________________________________
>> Ale mailing list
>> Ale at ale.org
>> http://mail.ale.org/mailman/listinfo/ale
>> See JOBS, ANNOUNCE and SCHOOLS lists at
>> http://mail.ale.org/mailman/listinfo
>>
>>
>
>
> --
>   Ed Cashin <ecashin at noserose.net>
>   http://noserose.net/e/
>   http://www.coraid.com/
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20131112/7c6ed672/attachment.html>


More information about the Ale mailing list