Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

bash: how to flush the output from command `tee`

3,260 views
Skip to first unread message

lihao

unread,
Mar 25, 2010, 3:21:06 PM3/25/10
to
Below is my pipe line under bash(RHEL5):

/path/to/my_script.sh 2>/dev/null | tee /path/to/log_file

I want to check the output from script '/path/to/my_script.sh'
immediately without having to wait for the buffer to be full. Is there
any bash configuration to handle this and only to this script [not to
the whole bash environment].

BTW. most of the output in the script "/path/to/my_script.sh" are from
the 'echo' command.

Thanks in advance,
lihao

pk

unread,
Mar 25, 2010, 3:17:37 PM3/25/10
to
lihao wrote:

Try

man stdbuf

there is an example similar to yours near the end.

Janis Papanagnou

unread,
Mar 25, 2010, 3:31:45 PM3/25/10
to
lihao wrote:
> Below is my pipe line under bash(RHEL5):
>
> /path/to/my_script.sh 2>/dev/null | tee /path/to/log_file
>
> I want to check the output from script '/path/to/my_script.sh'
> immediately without having to wait for the buffer to be full. Is there
> any bash configuration to handle this and only to this script [not to
> the whole bash environment].

In bash; not that I know of.

I use a pty. If you like, have a look at the book "Advanced Programming in
the UNIX Environment". The source code of the pty program from the book are
available online. Google for it.

Janis

Sidney Lambe

unread,
Mar 25, 2010, 4:06:22 PM3/25/10
to

Maybe you could have those echos in the script also echo to,
say, /dev/pts/4

At the prompt, from /dev/pts/5:

echo -e "\n\nfoo\n" > /dev/pts/4

Output at /dev/pts/4

root:/root:
$

foo

Ctrl-c to exit.

Sid

Sidney Lambe

unread,
Mar 25, 2010, 4:35:10 PM3/25/10
to

Wait a second. They are already echoing to whatever pty you
are running the script from. Where else?
I guess I'm not following this and should just shut up.

Sid


Sven Mascheck

unread,
Mar 25, 2010, 7:39:22 PM3/25/10
to
lihao wrote:

> /path/to/my_script.sh 2>/dev/null | tee /path/to/log_file
>
> I want to check the output from script '/path/to/my_script.sh'
> immediately without having to wait for the buffer to be full.

> [...] BTW. most of the output in the script "/path/to/my_script.sh"


> are from the 'echo' command.

In that case, sh -c "echo x;sleep 1"|tee, I can't see any block buffering.
Not even with sh -c "echo x|grep .;sleep 1"|tee.
What and how many commands in your script are fully buffered?

foo

unread,
Jul 30, 2010, 11:32:51 AM7/30/10
to
... | tee /dev/stderr | tee /path/to/log_file ?


Janis Papanagnou

unread,
Jul 30, 2010, 12:23:33 PM7/30/10
to
On 30/07/10 17:32, foo wrote:
> ... | tee /dev/stderr | tee /path/to/log_file ?
>
>

pty

Icarus Sparry

unread,
Jul 30, 2010, 12:54:56 PM7/30/10
to

pty is very very good.

A simpler answer in this case might be multitee.

... | multitee 0-1,2,3 3>/path/to/log_file

It might even be the case that the OP's 'tee' command would work

... | tee /dev/stderr /path/to/log_file

(I am guessing that the OP would be actually running
... | tee /dev/stderr | tee /path/to/log_file | something
as otherwise they will be getting two copies of the output of ..., one on
stderr and one on stdout)

bardy

unread,
Jul 31, 2010, 11:00:17 AM7/31/10
to
Or simply:

cmd 2>/dev/null | tee /dev/stderr > file.log

0 new messages