简体   繁体   English

wget:下载实时txt文件

[英]wget: downloading a LIVE txt file

I have this line at the end of my bash script: 我的bash脚本的末尾有这一行:

wget -q $URL -Y off

where URL is the path to a LIVE txt file that contains the console output for my bash script. URL是一个LIVE txt文件的路径,该文件包含我的bash脚本的控制台输出。

Clarification on LIVE txt file : 澄清 LIVE txt文件

This txt file keeps updating along the process since it stores the console output. 由于该txt文件存储了控制台输出,因此它会随着过程不断更新。 My shell script contains some "heavy" programs so the console output is very lengthy and the txt file will need some time to be generated (probably 3~5 seconds delay). 我的Shell脚本包含一些“繁重的”程序,因此控制台输出非常冗长,而txt文件将需要一些时间才能生成(可能需要3到5秒的延迟)。

Problem : sometimes I get incomplete txt file which only contains small portion of the final txt file. 问题 :有时我得到的txt文件不完整,仅包含最终txt文件的一小部分。 (it is expected to get everything before the wget command) And interesting enough, most of the incomplete txt files I downloaded is stuck at line 9999. I don't know whether this is limitation or not, but it appears to be fine if the console output is below 5k lines. (应该在wget命令之前得到所有内容)有趣的是,我下载的大多数不完整的txt文件都停留在第9999行。我不知道这是否是限制,但是如果控制台输出低于5k行。

Question: Is there a way to make wget wait for a specific time? 问题:有没有办法让wget等待特定时间?

ps I know the there is a timeout option -T for wget and the default is 900 seconds. ps我知道wget有一个超时选项-T ,默认值为900秒。 But my problem is not related to the slow connection but the delay of generating the file. 但是我的问题与缓慢的连接无关,而是与生成文件的延迟有关。

If this wget statement is running as part of the script that is generating the output, you are probably running into some sort of output buffering issue...that is, since the script has not yet exited, output has not yet been flushed. 如果此wget语句作为生成输出的脚本的一部分运行,则您可能会遇到某种输出缓冲问题……也就是说,由于脚本尚未退出,因此尚未刷新输出。

How are you redirecting output? 您如何重定向输出? One way would be to wrap everything other than the wget statement in a subshell and redirect the output of that : 一种方法是包装比其他一切wget声明在子shell和重定向输出:

#!/bin/sh

(
  a bunch
  of commands
) > output 2>&1

wget -q $URL ...

This ensures that the other commands have completed and the containing shell has exited by the time the wget runs. 这样可以确保其他命令已完成, 并且wget运行时已退出包含外壳程序的外壳

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

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