簡體   English   中英

Wget下載多個域和文件

[英]Wget Download for Multiple Domains and Files

我需要從另一個文件中列出的每個域中下載文件列表。 我已經嘗試了很多次,但還是失敗了。

示例列出了要下載的文件(例如,file.txt):

1.jpg
2.jpg
3.jpeg
4.bmp
5.gif

域的示例列表(例如url.lst):

google.com
google.co.in
google.com.br

劇本:

#!/bin/bash
# Create an array files that contains list of filenames

urls=`cat "url.lst"`
files=`cat "file.txt"`

   for ((file in "${files[@]}" && url in "${urls[@]}"));   do 
        wget "${url}${file}"
   done

我想獲取它,以便它生成並運行以下命令:

wget google.com/1.jpg
wget google.com/2.jpg
wget google.com/3.jpeg
wget google.com/4.bmp
wget google.com/5.gif
wget google.co.in/1.jpg
wget google.co.in/2.jpg
wget google.co.in/3.jpeg
wget google.co.in/4.bmp
wget google.co.in/5.gif
wget google.com.br/1.jpg
wget google.com.br/2.jpg
wget google.com.br/3.jpeg
wget google.com.br/4.bmp
wget google.com.br/5.gif

您正在這里進行幾件事。 首先,您讀取的變量不是在創建數組。 您將得到一個字符串,該字符串將受到單詞拆分和通配符等的限制。 其次,您將需要分別執行兩個文件循環,而不是嘗試在單個命令中執行。

要修復第一部分,我建議使用readarraymapfile ,第二個建議使用嵌套循環,例如:

readarray -t urls < url.lst
readarray -t files < file.txt

for dom in "${urls[@]}"; do
    for path in "${files[@]}"; do
        wget "$dom/$path"
    done
done

或者您可以將外部for循環替換for while循環,並跳過其中的readarray之一

readarray -t files < file.txt

while read -r url; do
    for path in "${files[@]}"; do
        wget "$url/$path"
    done
done < url.lst

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM