在 bash 脚本仍在运行时强制将输出刷新到文件 [英] Force flushing of output to a file while bash script is still running

查看:28
本文介绍了在 bash 脚本仍在运行时强制将输出刷新到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小脚本,它每天由 crontab 使用以下命令调用:

I have a small script, which is called daily by crontab using the following command:

/homedir/MyScript &> some_log.log

此方法的问题在于 some_log.log 仅在 MyScript 完成后创建.我想在程序运行时将程序的输出刷新到文件中,以便我可以执行诸如

The problem with this method is that some_log.log is only created after MyScript finishes. I would like to flush the output of the program into the file while it's running so I could do things like

tail -f some_log.log

并跟踪进度等

推荐答案

bash 本身实际上永远不会将任何输出写入您的日志文件.相反,它作为脚本的一部分调用的命令将每个单独写入输出并在需要时刷新.所以你的问题实际上是如何强制 bash 脚本中的命令刷新,这取决于它们是什么.

bash itself will never actually write any output to your log file. Instead, the commands it invokes as part of the script will each individually write output and flush whenever they feel like it. So your question is really how to force the commands within the bash script to flush, and that depends on what they are.

这篇关于在 bash 脚本仍在运行时强制将输出刷新到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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