【问题标题】:A bash script for multiple wget commands [duplicate]用于多个 wget 命令的 bash 脚本 [重复]
【发布时间】:2016-03-08 15:34:03
【问题描述】:

我有多个(超过 100 个)类似的:

wget -q -nH --cut-dirs=5 -r -l0 -c -N -np -R 'index*' -erobots=off --retr-symlinks http://heasarc.gsfc.nasa.gov/FTP/swift/data/obs/2009_02//00031327004/auxil/
wget -q -nH --cut-dirs=5 -r -l0 -c -N -np -R 'index*' -erobots=off --retr-symlinks http://heasarc.gsfc.nasa.gov/FTP/swift/data/obs/2009_01//00031327001/uvot/
wget -q -nH --cut-dirs=5 -r -l0 -c -N -np -R 'index*' -erobots=off --retr-symlinks http://heasarc.gsfc.nasa.gov/FTP/swift/data/obs/2010_12//00031856009/uvot/
wget -q -nH --cut-dirs=5 -r -l0 -c -N -np -R 'index*' -erobots=off --retr-symlinks http://heasarc.gsfc.nasa.gov/FTP/swift/data/obs/2008_01//00031043003/uvot/
wget -q -nH --cut-dirs=5 -r -l0 -c -N -np -R 'index*' -erobots=off --retr-symlinks http://heasarc.gsfc.nasa.gov/FTP/swift/data/obs/2012_01//00032237004/uvot/

有人告诉我,这可以使用 bash 脚本快速轻松地完成,如果可能的话,有人可以给我一个示例,用于多个 wget 命令吗?我需要在脚本中包含什么?为我的 n00b 问题道歉,但是......我是其中之一!

【问题讨论】:

  • 有多相似?每次通话有什么不同?只是网址?
  • 我会用几行更新答案。
  • 你在一个文本文件中拥有所有这些 URL 吗?
  • 是的,都在一个普通的 .txt 文件中
  • bash your-file-here.txt,如果您只想将其作为脚本运行。

标签: bash wget


【解决方案1】:

假设您的菜鸟问题是关于加快处理时间,

您可以在后台为它们生成多个进程 &wait

wget firsturl &
wget secondurl &
...
wait

【讨论】:

  • 我更喜欢 bash 脚本。
  • 它是一个 bash 脚本,只需将 firsturl 替换为您使用的任何内容
  • 这可以放在一个文本文件中作为脚本运行吗?
  • 是的,只需将 ... 替换为您的所有网址,并以 & 结束每一行
【解决方案2】:

假设您的 URL 列表如下所示:

http://heasarc.gsfc.nasa.gov/FTP/swift/data/obs/2009_02//00031327004/auxil/
http://heasarc.gsfc.nasa.gov/FTP/swift/data/obs/2009_01//00031327001/uvot/
http://heasarc.gsfc.nasa.gov/FTP/swift/data/obs/2010_12//00031856009/uvot/
http://heasarc.gsfc.nasa.gov/FTP/swift/data/obs/2008_01//00031043003/uvot/
http://heasarc.gsfc.nasa.gov/FTP/swift/data/obs/2012_01//00032237004/uvot/

只需 read 使用 while 循环从文本文件中获取您的网址:

#!/bin/bash
while read url; do
    wget -q -nH --cut-dirs=5 -r -l0 -c -N -np -R 'index*' -erobots=off --retr-symlinks "$url"
done < urls.txt

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多