[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: output redirection with process substitution asynchronous?
From: |
Greg Wooledge |
Subject: |
Re: output redirection with process substitution asynchronous? |
Date: |
Mon, 7 Dec 2009 08:41:49 -0500 |
User-agent: |
Mutt/1.4.2.3i |
> pjodrr wrote:
> > how can I prefix every line of output of some command with a
> > timestamp?
Mark Herbert wrote:
> What is wrong with the following:
>
> prefix_with_date ()
> {
> while read; do
> printf '%s: %s\n' "$(date)" "$REPLY";
> done
> }
>
> seq 4 | prefix_with_date
> ls | prefix_with_date
On Sun, Dec 06, 2009 at 12:49:44AM -0800, pjodrr wrote:
> fifo=$(mktemp -u) || exit
> mkfifo $fifo || exit
> trap "rm -f $fifo" 0
> trap exit 1 2 15
> while read line; do echo "$(date): $line"; done < $fifo &
> prefix_pid=$!
> seq 4 > $fifo
> wait $prefix_pid
>
> Or how would you accomplish this?
What on earth is "this"? If you just want to prefix every line of some
command's output with a timestamp, and you're not willing to use
multilog (http://cr.yp.to/daemontools.html) or a perl one-liner, then
the bash function Mark gave is quite reasonable (maybe use "read -r"
instead of "read" to preserve backslashes).
The obvious disadvantage of doing this in bash is that bash has to
invoke an external date(1) command for every line it processes.
A perl one-liner could do it with built-in time functions, and of
course multilog is a single program.
It seems you have some other goal in mind, though, besides "prefix every
line of output of some command with a timestamp". What is the point of
all this command substitution and FIFO trickery?
- Re: output redirection with process substitution asynchronous?, (continued)
- Re: output redirection with process substitution asynchronous?, pjodrr, 2009/12/05
- Re: output redirection with process substitution asynchronous?, pk, 2009/12/05
- Re: output redirection with process substitution asynchronous?, pjodrr, 2009/12/06
- Re: output redirection with process substitution asynchronous?, pk, 2009/12/06
- Re: output redirection with process substitution asynchronous?, Marc Herbert, 2009/12/07
- Re: output redirection with process substitution asynchronous?,
Greg Wooledge <=
- Re: output redirection with process substitution asynchronous?, Marc Herbert, 2009/12/07
- Message not available
- Re: output redirection with process substitution asynchronous?, DennisW, 2009/12/07
- Message not available
- Re: output redirection with process substitution asynchronous?, pjodrr, 2009/12/08
- Re: output redirection with process substitution asynchronous?, Marc Herbert, 2009/12/08
- Message not available
- Re: output redirection with process substitution asynchronous?, pjodrr, 2009/12/08
- Re: output redirection with process substitution asynchronous?, pjodrr, 2009/12/12
- Message not available
- Re: output redirection with process substitution asynchronous?, pk, 2009/12/07
- Re: output redirection with process substitution asynchronous?, Marc Herbert, 2009/12/08
- Message not available
- Re: output redirection with process substitution asynchronous?, pjodrr, 2009/12/08