简体   繁体   English

如何停止写入BASH中的日志文件?

[英]How to stop writing to log file in BASH?

I'm using this code to write all terminal's output to the file 我正在使用此代码将所有终端的输出写入文件

exec > >(tee -a "${LOG_FILE}" )
exec 2> >(tee -a "${LOG_FILE}" >&2)

How to tell it to stop? 如何告诉它停止? If, for example, I don't want some output to get into log.. 例如,如果我不希望某些输出进入日志。

Thank you! 谢谢!

It's not completely clear what your goal is here, but here is something to try. 目前尚不清楚您的目标是什么,但是可以尝试一下。

Do you know about the script utility? 您知道script实用程序吗? You can run script myTerminalOutputFile and any commands and output after that will be captured to myTerminalOutputFile . 您可以运行script myTerminalOutputFilescript myTerminalOutputFile所有命令和输出都将捕获到myTerminalOutputFile The downside is that it captures everything. 缺点是它捕获了所有内容。 You'll see funny screen control chars like ^[[5m;27j . 您会看到有趣的屏幕控制字符,例如^[[5m;27j So do a quick test to see if that works for you. 因此,请快速测试一下是否适合您。

To finish capturing output just type exit and you are returned to you parent shell cmd-line. 要完成捕获输出,只需键入exit然后返回到您的父shell cmd-line。

Warning: check man script for details about the inherent funkyness of your particular OS's version of script. 警告:请检查man script以获取有关特定OS版本的脚本固有的时髦性的详细信息。 Some are better than others. 有些比其他更好。 script -k myTerminalOutputFile may work better in this case. 在这种情况下, script -k myTerminalOutputFile可能会更好地工作。

IHTH 高温超导

您可以通过“ sed”管道传输,然后通过tee进入日志文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM