延迟wget进度条显示间隔

问题描述 投票:0回答:2

如何延迟wget进度条更新/刷新间隔?

默认情况下,它每毫秒更新一次,并且在作业脚本中运行时,每个更新都将作为单行捕获到 STDOUT 文件中,从而导致作业脚本 STDOUT 文件变大。我不想完全禁用进度条,因为我仍然想知道不同时间的进度。

wget
2个回答
21
投票

wget
知道
--progress
选项,它允许您稍微调整输出设置。手册页摘录:

   --progress=type
       Select the type of the progress indicator you wish to use.  Legal indicators are
       "dot" and "bar".

       [...]The "bar" indicator is used by default.  It draws an ASCII progress bar graphics
       (a.k.a "thermometer" display) indicating the status of retrieval.  If the output is
       not a TTY, the "dot" bar will be used by default.

       Use --progress=dot to switch to the "dot" display.  It traces the retrieval by
       printing dots on the screen, each dot representing a fixed amount of downloaded data.

       The progress type can also take one or more parameters.  The parameters vary based on
       the type selected.  Parameters to type are passed by appending them to the type
       sperated by a colon (:) like this: --progress=type:parameter1:parameter2.

       When using the dotted retrieval, you may set the style by specifying the type as
       dot:style.  Different styles assign different meaning to one dot.  With the "default"
       style each dot represents 1K, there are ten dots in a cluster and 50 dots in a line.
       The "binary" style has a more "computer"-like orientation---8K dots, 16-dots clusters
       and 48 dots per line (which makes for 384K lines).  The "mega" style is suitable for
       downloading large files---each dot represents 64K retrieved, there are eight dots in
       a cluster, and 48 dots on each line (so each line contains 3M).  If "mega" is not
       enough then you can use the "giga" style---each dot represents 1M retrieved, there
       are eight dots in a cluster, and 32 dots on each line (so each line contains 32M).

       With --progress=bar, there are currently two possible parameters, force and noscroll.

       When the output is not a TTY, the progress bar always falls back to "dot", even if
       --progress=bar was passed to Wget during invokation. This behaviour can be overridden
       and the "bar" output forced by using the "force" parameter as --progress=bar:force.

       By default, the bar style progress bar scroll the name of the file from left to right
       for the file being downloaded if the filename exceeds the maximum length allotted for
       its display.  In certain cases, such as with --progress=bar:force, one may not want
       the scrolling filename in the progress bar.  By passing the "noscroll" parameter,
       Wget can be forced to display as much of the filename as possible without scrolling
       through it.

       Note that you can set the default style using the "progress" command in .wgetrc.
       That setting may be overridden from the command line.  For example, to force the bar
       output without scrolling, use --progress=bar:force:noscroll

我建议阅读整篇文章以了解

wget
的进度表如何工作,但简而言之,以下是要点:

  • 如果输出不是 tty,
    wget
    将使用
    dot
    显示方法
  • dot
    显示方法每下载 X 个字节数就会显示一个
    .
  • X 可以通过将
    --progress=dot:<style>
    传递给
    wget
    调用来调整
  • style
    可以是以下之一:
    • default
      :每点 1KB
    • binary
      :每点 8KB
    • mega
      :每点 64KB
    • giga:
      每点 1MB

总而言之,为了减少下载大文件时的输出,您可以按如下方式调用 wget:

$> wget --progress=dot:mega <url>

0
投票

这是一个很老的问题,但我有另一个解决方案。您可以使用 awk 来过滤输出:

wget https://some.large.file -O file.bin 2>&1 | awk 'BEGIN{t=0;l=""}systime()-t>1{print $0;t=systime()}/.+/{l=$0}END{print l}'

让我们解释一下:

  • 2>&1: wget 输出进度到 stderr,所以我们需要将 stderr 重定向到 stdout 以使用管道
  • awk 是处理纯文本的有用工具。我们在这里用它来减慢输出速度。您可以将 1 修改为您喜欢的任何其他数字,它代表更新间隔(以秒为单位)。
  • 变量“t”存储最后的输出时间戳
  • 变量“l”存储最后一个非空行,您可能希望最后一行知道最终状态
© www.soinside.com 2019 - 2024. All rights reserved.