[ale] line timestamp command

Horkan Smith ale at horkan.net
Tue Nov 19 15:11:46 EST 2013


Hi Scott,

Just scratching an itch, that's all.  If it's usefull, great!  If not, that's ok too - I had a little fun writing it, and I learned about a new (to me) call to change the stdout buffer flow thanks to Ed C.

Agreed, a proper command should offer more date formats.  Adding new formats wouldn't be that bad (man strftime), but you might need to add some sanity checks around a true free-form approach like the 'date' command.  If somebody actually has a use for it that way, let me know and I'll take a look.  For that matter, if anybody just wants a copy w/ the fixes that Ed and I talked about, let me know and I'll send it along.

Would I use it?  Hmm.... not sure.  I've certainly written a lot of one-use-scripts that used the date command to let me know when stuff happened, but I'd never had the insight to do it the way you've suggested.  Now that the idea's in my mental toolbox, I'll probably come up w/ a reason to apply it.  8-)

thanks!
   horkan

p.s. gawk -e "{ print strftime(\"%D %T\"), \$0; }"

On Tue, Nov 19, 2013 at 12:26:37PM -0500, Scott Plante wrote:
> You are very kind to go to all that trouble. In many cases I'm still using the commands I was using 10-30 years ago, and I mostly wanted to make sure a fairly standard command to do it hadn't crept in the mix along the way. Thanks also to Doug for the ruby snippet and the other help. In my case I don't have root on this particular box so using logger would have been more trouble than it's worth but I do want to learn more about customizing syslog. I see uucp is still one of the standard syslog facilities! That takes me back. 
> 
> 
> If this C program were to be a standard util included in Linux, I'd like to see the same time format options as the date command. Does this seem like something of general use? I can see piping a slow rsync to it or other commands that generate output periodically. Usually I suppose it would feed to a proper logging system that would put the timestamps on, but it still seems useful for ad hoc usage. 
> 
> 
> Scott 
> 
> ----- Original Message -----
> 
> From: "Horkan Smith" <ale at horkan.net> 
> To: "Atlanta Linux Enthusiasts" <ale at ale.org> 
> Sent: Wednesday, November 13, 2013 7:43:52 AM 
> Subject: Re: [ale] line timestamp command 
....snip....
> 
> ------end------ 
> 
> On Tue, Nov 12, 2013 at 01:34:22PM -0500, Scott Plante 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 

-- 
Horkan Smith
678-777-3263 cell, ale at horkan.net


More information about the Ale mailing list