質問

I'm trying to execute a long list of repetitive commands on Terminal.

The commands look like this:

wget 'http://api.tiles.mapbox.com/v3/localstarlight.hl2o31b8/-180,52,9/1280x1280.png' -O '/Volumes/Alaya/XXXXXXXXX/Downloads/MapTiles/Tile (52.-180) 0.png' \ 
wget 'http://api.tiles.mapbox.com/v3/localstarlight.hl2o31b8/-177,52,9/1280x1280.png' -O '/Volumes/Alaya/XXXXXXXXX/Downloads/MapTiles/Tile (52.-177) 1.png' \

If I copy the entire list into Terminal, it executes them all but seems to do it in such a rush that some only get partially downloadeed, and some missed out entirely. It doesn't seem to take them one by one and wait until each is finished before attempting the next.

I tried putting them entire list into a shell script and running it, but then for some reason it seems to download everything, but only produces one file, and looking at the output, it seems to be trying to save each file under the same filename:

2014-03-29 09:56:31 (4.15 MB/s) - `/Volumes/Alaya/XXXXXXXX/Downloads/MapTiles/Tile (52.180) 120.png' saved [28319/28319]

    --2014-03-29 09:56:31--  http://%20%0Dwget/
    Resolving  \rwget... failed: nodename nor servname provided, or not known.
    wget: unable to resolve host address ` \rwget'
    --2014-03-29 09:56:31--  http://api.tiles.mapbox.com/v3/localstarlight.hl2o31b8/171,52,9/1280x1280.png
    Reusing existing connection to api.tiles.mapbox.com:80.
    HTTP request sent, awaiting response... 200 OK
    Length: 33530 (33K) [image/jpeg]
    Saving to: `/Volumes/Alaya/XXXXXXXX/Downloads/MapTiles/Tile (52.180) 120.png'

    100%[======================================>] 33,530      --.-K/s   in 0.008s  

    2014-03-29 09:56:31 (3.90 MB/s) - `/Volumes/Alaya/XXXXXXXX/Downloads/MapTiles/Tile (52.180) 120.png' saved [33530/33530]

    --2014-03-29 09:56:31--  http://%20%0Dwget/
    Resolving  \rwget... failed: nodename nor servname provided, or not known.
    wget: unable to resolve host address ` \rwget'
    --2014-03-29 09:56:31--  http://api.tiles.mapbox.com/v3/localstarlight.hl2o31b8/174,52,9/1280x1280.png
    Reusing existing connection to api.tiles.mapbox.com:80.
    HTTP request sent, awaiting response... 200 OK
    Length: 48906 (48K) [image/jpeg]
    Saving to: `/Volumes/Alaya/XXXXXXXX/Downloads/MapTiles/Tile (52.180) 120.png'

    100%[======================================>] 48,906      --.-K/s   in 0.01s   

    2014-03-29 09:56:31 (4.88 MB/s) - `/Volumes/Alaya/XXXXXXXX/Downloads/MapTiles/Tile (52.180) 120.png' saved [48906/48906]

    --2014-03-29 09:56:31--  http://%20%0Dwget/
    Resolving  \rwget... failed: nodename nor servname provided, or not known.
    wget: unable to resolve host address ` \rwget'
    --2014-03-29 09:56:31--  http://api.tiles.mapbox.com/v3/localstarlight.hl2o31b8/177,52,9/1280x1280.png
    Reusing existing connection to api.tiles.mapbox.com:80.
    HTTP request sent, awaiting response... 200 OK
    Length: 45644 (45K) [image/jpeg]
    Saving to: `/Volumes/Alaya/XXXXXXXX/Downloads/MapTiles/Tile (52.180) 120.png'

    100%[======================================>] 45,644      --.-K/s   in 0.01s   

    2014-03-29 09:56:31 (4.36 MB/s) - `/Volumes/Alaya/XXXXXXXX/Downloads/MapTiles/Tile (52.180) 120.png' saved [45644/45644]

So it's saving every file to this name: Tile (52.180) 120.png

Note that it doesn't do this if I put in each command separately...so I don't understand why it's doing that.

Can someone tell me how to execute this list of commands so that it does each one properly?

Thanks!

役に立ちましたか?

解決

Your file should look like this:

#!/bin/bash
wget -q 'http://api.tiles.mapbox.com/v3/localstarlight.hl2o31b8/-180,52,9/1280x1280.png' -O 'a.png'
wget -q 'http://api.tiles.mapbox.com/v3/localstarlight.hl2o31b8/-177,52,9/1280x1280.png' -O 'b.png'

BUT... you have a backslash at the end of each wget line, which is a continuation character for long lines and which you don't need. Remove it.

Essentially you are asking wget to get a file and then another file called wget and then another file and then another file. Your script only does a single wget - the first one. All the other wget commands are seen as parameters to the first wget because of the continuation character.

You are doing this:

wget URL file wget URL file wget URL file

他のヒント

Quoting from the log you've posted:

http://%20%0Dwget/

This suggests that your script contains CR+LF line endings. Remove those before executing the script:

sed $'s/\r//' scriptname

or

tr -d '\r' < scriptname
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top