/频繁的unix tee命令如何将stdout终端输出写入文件?如果输出太大 [英] How does/frequent unix tee command write stdout terminal output to file? if the output is too big

查看:117
本文介绍了/频繁的unix tee命令如何将stdout终端输出写入文件?如果输出太大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一些工具stdout重定向到tee命令,以便可以在终端以及日志文件中看到当前进度

I am redirecting some tool stdout to tee command so that current progress can be seen on terminal as well as in the log file

这是我正在运行工具的代码段,其stdout被馈送到tee命令,并且该代码段是从tcl脚本编写的.

Here is the code snippet where I am running tool and its stdout is fed to tee command and this code snippet is written from tcl script.

$(EH_SUBMIT) $(ICC_EXEC) $(OPTIONS) -f ./scripts/$@.tcl | tee -i ./logs/$@.log

我可以在终端上看到当前的实时进度,但是在日志文件中看不到相同的观察结果!并将stdout逐块写入日志文件

I can see current real time progress on the terminal but the same observation is not seen in the log file! and it writes stdout to log file chunk by chunk

tee如何工作?它是按块写入还是按时间写入,还是两者同时写入? 如果是块,最小块大小是多少?如果是时间,那么最短持续时间是多少?

How does tee work? Does it write by blocks or time or both? If block what is the minimum block size? If it is time what is minimum duration?

我需要解析实时日志条目以进行某些数据分析(当我通过tail -f读取日志文件,然后随着日志文件的增长推送新数据).

I need to parse real time log entries for some data analytics(as I read log file via tail -f and then push new data as the log file grows).

推荐答案

除非程序自行处理缓冲,否则IO流的缓冲将在libc中处理.标准行为是:如果缓冲区输出到终端,则为明智的行;如果缓冲区到非终端(即文件或管道),则为明智的块输出.这就是输出如您所描述的那样出现在日志文件中的原因:逐块.此行为是为了优化性能.

Unless programs handle buffering on their own, buffering of IO streams is handled in the libc. The standard behaviour is: Buffer output line wise if it goes to a terminal, buffer output block wise if it goes to a non-terminal, meaning a file or a pipe. That's why the output appears in log file as you described it: chunk by chunk. This behaviour is for performance optimization.

在Linux上, stdbuf 命令可用于运行带有调整后的缓冲区.您需要像这样运行程序:

On Linux the stdbuf command can be used to run a program with adjusted buffers. You need to run your program like this:

stdbuf -oL your_program >> your.log &
tail -f your.log

-oL表示按行缓冲stdout.

-oL means buffer stdout linewise.

这篇关于/频繁的unix tee命令如何将stdout终端输出写入文件?如果输出太大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆