【问题标题】:Wget with input-file and output-document带有输入文件和输出文件的 Wget
【发布时间】:2010-01-12 02:26:22
【问题描述】:

我有一个 URL 列表,我想使用 --input-file 将其输入 wget。

但是我不知道如何同时控制 --output-document 值, 如果您一一发出命令,这很简单。 我想将每个文档保存为其 URL 的 MD5。

 cat url-list.txt | xargs -P 4 wget

xargs 之所以存在,是因为我还想利用 max-procs 功能进行并行下载。

【问题讨论】:

    标签: bash wget xargs


    【解决方案1】:

    不要使用cat。您可以让xargs 从文件中读取。来自man 页面:

    --arg-file=文件 -一份文件 从文件而不是标准输入中读取项目。如果你使用这个 选项,运行命令时标准输入保持不变。其他- 明智的做法是,标准输入从 /dev/null 重定向。

    【讨论】:

    • @btk: xargs -P 4 -a url-list.txt wget
    【解决方案2】:

    使用循环怎么样?

    while read -r line
    do
       md5=$(echo "$line"|md5sum)
       wget ... $line ... --output-document $md5 ......
    done < url-list.txt
    

    【讨论】:

    • 我认为我的问题只是今天才发现 xargs,我没有明白,但您的回答给了我线索,让 xargs 调用具有所有 wget 逻辑的 bash 脚本。
    【解决方案3】:

    在您的问题中,您使用 -P 4 表示您希望您的解决方案并行运行。 GNU Parallel http://www.gnu.org/software/parallel/ 可以帮助你:

    cat url-list.txt | parallel 'wget {} --output-document "`echo {}|md5sum`"'
    

    【讨论】:

      【解决方案4】:

      你可以这样做:

      cat url-list.txt |读取网址时; 做 wget $url -O $( echo "$url" | md5 ); 完成

      祝你好运

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多