如何在不使用回车的情况下从日志文件显示 rsync 进度?
我有一个来自 rsync 命令的日志文件,其中包含进度。运行此进度时,会更新同一行上的显示信息。当我捕获此命令的输出时,我得到一个在终端上正常显示为 cat
的文件(所有退格键和重新编辑都会重播),但我希望能够使用 grep
文件并对其进行处理,以便我看到所有退格编辑命令。如何处理该文件以删除所有进度更新并仅获取具有最终编辑的文件?
I have a log file from rsync command with progress on. When running this progress updates the display information on the same line. When I capture the output from this command I get a file that displays normally with cat
on a terminal (all the backspaces and re-edits are replayed) but I want to be able to use grep
on the file and process it so I see all the backspace edit commands. How can I process the file to remove all the progress updates and just get a file that has the final edits?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想查看捕获的文件的外观,而进度线不会覆盖之前的进度线:
这可能会产生如下所示的结果:
如果您只想查看进度消息的最后一步并消除之前的进度线:
这可能看起来像this:
您可以使用
--log-file=name
选项运行rsync
来捕获文件中的日志信息。将“名称”替换为您想要的名称。您可以使用log-file-format
选项控制记录的信息(有关详细信息,请参阅man rsyncd.conf
中的日志格式部分)。在我的系统上,默认的 rsync 日志文件如下所示:
If you want to see what your captured file looks like without the progress lines overwriting the previous ones:
which might yield something like this:
If you want to see just the final step of the progress message and eliminate the previous ones:
Which might look like this:
You can run
rsync
with the--log-file=name
option to capture log information in a file. Replace "name" with the name that you want. You can control the information that gets logged using thelog-file-format
option (see the log format section inman rsyncd.conf
for details).On my system the default
rsync
log file looks like this:首先,我猜出于各种原因,保留进度指示器对您来说很重要,因为最简单的解决方案就是将其关闭。其次,我假设没有办法告诉 rsync 将除进度指示器之外的所有内容写出到与屏幕上显示的内容不同的单独文件中。最后,我假设您根本不希望稍后使用其他工具处理的日志文件中包含任何进度指示器内容。
考虑到这两个假设,您可以通过基本上在每行中查找 \b 或 \r 字符并丢弃具有这些字符的所有行来删除进度指示器。这可以像 grep 命令行一样简单,如下所示:
这假定您有一个支持
"$(...)"
样式参数替换的 shell 和一个支持"$(...)"
样式参数替换的 echo 命令>-e 参数。First, I'm guessing the progress indicators are important for you to keep for various reasons, because the simplest solution is to just turn them off. Secondly, I'm assuming there is no way to tell rsync to write out a log with everything but the progress indicators to a separate file from what it shows on the screen. Lastly, I'm assuming that you do not want any of the progress indicator stuff at all in the log file you later process with other tools.
Given these two assumptions, you can strip out the progress indicators by basically looking through each line for \b or \r characters and tossing all lines that have those characters. This can be as simple as a grep command line that looks like this:
This presupposes you have a shell that supports
"$(...)"
style argument substitution and an echo command that supports the-e
arguments.