Maciej Kravchyk
Maciej Kravchyk

Reputation: 16657

bash: wget in a loop, strange addresses

I wrote a small bash script that downloads plugins from wordpress plugin directory based on a plugin-name list. It works, but it seems like wget is called more times than neeeded with strange arguments.

#!/bin/bash

pluginlist="list" #plugin list, line by line

outputdir="output"

urlprefix="http://downloads.wordpress.org/plugin"

ua="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.6) Gecko/20070802 SeaMonkey/1.1.4"

if [ ! -f "$pluginlist" ]; then 

    echo List \file "$pluginlist" does not exist\!; 
    exit
fi

while read plugin_name; do

    wget -U $ua -O $outputdir/$plugin_name."zip" $urlprefix/$plugin_name."zip"

done <$pluginlist

echo \done

Sample output:

--2015-11-23 22:47:45--  http://(x11;/
Resolving (x11; ((x11;)... failed: Name or service not known.
wget: unable to resolve host address ‘(x11;’
--2015-11-23 22:47:45--  http://u;/
Resolving u; (u;)... failed: Name or service not known.
wget: unable to resolve host address ‘u;’
--2015-11-23 22:47:45--  http://linux/
Resolving linux (linux)... failed: Name or service not known.
wget: unable to resolve host address ‘linux’
--2015-11-23 22:47:45--  http://i686;/
Resolving i686; (i686;)... failed: Name or service not known.
wget: unable to resolve host address ‘i686;’
--2015-11-23 22:47:45--  http://en-us;/
Resolving en-us; (en-us;)... failed: Name or service not known.
wget: unable to resolve host address ‘en-us;’
--2015-11-23 22:47:51--  ftp://rv/1.8.1.6)
           => ‘output/add-meta-tags.zip’
Resolving rv (rv)... failed: Name or service not known.
wget: unable to resolve host address ‘rv’
--2015-11-23 22:47:56--  http://gecko/20070802
Resolving gecko (gecko)... failed: Name or service not known.
wget: unable to resolve host address ‘gecko’
--2015-11-23 22:47:56--  http://seamonkey/1.1.4
Resolving seamonkey (seamonkey)... failed: Name or service not known.
wget: unable to resolve host address ‘seamonkey’
--2015-11-23 22:48:06--  http://downloads.wordpress.org/plugin/add-meta-tags.zip
Resolving downloads.wordpress.org (downloads.wordpress.org)... 66.155.40.188, 66.155.40.186, 66.155.40.187, ...
Connecting to downloads.wordpress.org (downloads.wordpress.org)|66.155.40.188|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://downloads.wordpress.org/plugin/add-meta-tags.zip [following]
--2015-11-23 22:48:07--  https://downloads.wordpress.org/plugin/add-meta-tags.zip
Connecting to downloads.wordpress.org (downloads.wordpress.org)|66.155.40.188|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 271770 (265K) [application/zip]
Saving to: ‘output/add-meta-tags.zip’

output/add-meta-tag 100%[=====================>] 265.40K   182KB/s   in 1.5s   

2015-11-23 22:48:09 (182 KB/s) - ‘output/add-meta-tags.zip’ saved [271770/271770]

FINISHED --2015-11-23 22:48:09--
Total wall clock time: 25s
Downloaded: 1 files, 265K in 1.5s (182 KB/s)

So it's getting a lot of strange addresses before it gets the correct one. I have no idea why this happens.

Upvotes: 0

Views: 210

Answers (1)

FatalError
FatalError

Reputation: 54591

You need to quote your user agent string:

wget -U "$ua" -O $outputdir/$plugin_name."zip" $urlprefix/$plugin_name."zip"

Otherwise, bash will split this on spaces and pass it to wget as multiple args... which it is trying to treat as URLs.

Upvotes: 2

Related Questions