如何在不使用回车的情况下从日志文件显示 rsync 进度?

发布于 2024-08-09 20:07:46 字数 201 浏览 2 评论 0原文

我有一个来自 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

复古式 2024-08-16 20:07:46

如果您想查看捕获的文件的外观,而进度线不会覆盖之前的进度线:

sed 's/\r/\n/g' capture-file

这可能会产生如下所示的结果:

created directory /some/dest/dir
filename

       32768   0%    0.00kB/s    0:00:00
     6717440  21%    6.38MB/s    0:00:03
    13139968  41%    6.25MB/s    0:00:02
    19791872  62%    6.28MB/s    0:00:01
    26214400  82%    6.24MB/s    0:00:00
    31784420 100%    6.25MB/s    0:00:04 (xfer#1, to-check=0/1)

sent 31788388 bytes  received 31 bytes  3346149.37 bytes/sec
total size is 31784420  speedup is 1.00

如果您只想查看进度消息的最后一步并消除之前的进度线:

sed 's/.*\r/\n/g' capture-file

这可能看起来像this:

created directory /some/dest/dir
filename

    31784420 100%    6.25MB/s    0:00:04 (xfer#1, to-check=0/1)

sent 31788388 bytes  received 31 bytes  3346149.37 bytes/sec
total size is 31784420  speedup is 1.00

您可以使用 --log-file=name 选项运行 rsync 来捕获文件中的日志信息。将“名称”替换为您想要的名称。您可以使用 log-file-format 选项控制记录的信息(有关详细信息,请参阅 man rsyncd.conf 中的日志格式部分)。

在我的系统上,默认的 rsync 日志文件如下所示:

2009/11/01 17:19:20 [23802] building file list
2009/11/01 17:19:20 [23802] created directory /some/dest/dir
2009/11/01 17:19:25 [23802] <f+++++++++ filename
2009/11/01 17:19:25 [23802] sent 31788388 bytes  received 31 bytes  3346149.37 bytes/sec
2009/11/01 17:19:25 [23802] total size is 31784420  speedup is 1.00

If you want to see what your captured file looks like without the progress lines overwriting the previous ones:

sed 's/\r/\n/g' capture-file

which might yield something like this:

created directory /some/dest/dir
filename

       32768   0%    0.00kB/s    0:00:00
     6717440  21%    6.38MB/s    0:00:03
    13139968  41%    6.25MB/s    0:00:02
    19791872  62%    6.28MB/s    0:00:01
    26214400  82%    6.24MB/s    0:00:00
    31784420 100%    6.25MB/s    0:00:04 (xfer#1, to-check=0/1)

sent 31788388 bytes  received 31 bytes  3346149.37 bytes/sec
total size is 31784420  speedup is 1.00

If you want to see just the final step of the progress message and eliminate the previous ones:

sed 's/.*\r/\n/g' capture-file

Which might look like this:

created directory /some/dest/dir
filename

    31784420 100%    6.25MB/s    0:00:04 (xfer#1, to-check=0/1)

sent 31788388 bytes  received 31 bytes  3346149.37 bytes/sec
total size is 31784420  speedup is 1.00

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 the log-file-format option (see the log format section in man rsyncd.conf for details).

On my system the default rsync log file looks like this:

2009/11/01 17:19:20 [23802] building file list
2009/11/01 17:19:20 [23802] created directory /some/dest/dir
2009/11/01 17:19:25 [23802] <f+++++++++ filename
2009/11/01 17:19:25 [23802] sent 31788388 bytes  received 31 bytes  3346149.37 bytes/sec
2009/11/01 17:19:25 [23802] total size is 31784420  speedup is 1.00
耶耶耶 2024-08-16 20:07:46

首先,我猜出于各种原因,保留进度指示器对您来说很重要,因为最简单的解决方案就是将其关闭。其次,我假设没有办法告诉 rsync 将除进度指示器之外的所有内容写出到与屏幕上显示的内容不同的单独文件中。最后,我假设您根本不希望稍后使用其他工具处理的日志文件中包含任何进度指示器内容。

考虑到这两个假设,您可以通过基本上在每行中查找 \b 或 \r 字符并丢弃具有这些字符的所有行来删除进度指示器。这可以像 grep 命令行一样简单,如下所示:

grep -ve "$(echo -ne '[\b\r]')" logfile

这假定您有一个支持 "$(...)" 样式参数替换的 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:

grep -ve "$(echo -ne '[\b\r]')" logfile

This presupposes you have a shell that supports "$(...)" style argument substitution and an echo command that supports the -e arguments.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文