/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
Try
man stdbuf
there is an example similar to yours near the end.
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
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
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
> /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?
pty
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)
cmd 2>/dev/null | tee /dev/stderr > file.log