A shell script for batch download of network images

Source: Internet
Author: User
By long Luo
Recently Weather ForecastProject, you need to download some weather icons from Yahoo, but because there are many icons, there are more than 80. Icons are stored on the Yahoo image website.

Thunder does not support HTTPS download. Although it can be downloaded in the browser, it is too slow to download in the browser. Therefore, a shell script for batch downloading image resources is written, which perfectly solves this problem.

The address rules for Yahoo weather chart are as follows: 'https: // s.yimg.com/zz/combo? A/I/US/NWS/weather/GR/'+ icon name

For example:

I used two methods to solve the problem of downloading. Although I haven't written shell scripts for a long time, I still have the awareness and foundation, and it is easier to write dozens of lines of code.

Method 1:
#!/bin/bash# #  Decription: #A Shell script used to download the imges from Internet.#  Author:#       Long Luo#  Date:#       2014-09-11 00:16:59#BASE_URL="https://s.yimg.com/zz/combo?a/i/us/nws/weather/gr/"# declare STIRNG variableSTRING="Beginning Image download..."#print var on screen echo $STRINGsleep 1echo "...."BIG_PNG="ds.png"PNG=".png"echo "url="${BASE_URL}echo "big png="${BIG_PNG}for ((i=0; i<49;i++)); doecho IMG_URL=${BASE_URL}${i}${BIG_PNG}echo "final url="${IMG_URL}curl ${BASE_URL}${i}${BIG_PNG} -o small/${i}${PNG}sleep 1done

Method 2:
# Method 2URL_ARRAY=('https://s.yimg.com/zz/combo?a/i/us/nws/weather/gr/0d.png''https://s.yimg.com/zz/combo?a/i/us/nws/weather/gr/1d.png')NAME_ARRAY=('file1.jpg''file2.jpg')ELEMENTS=${#URL_ARRAY[@]}for (( i=0;i<ELEMENTS;i++)); doecho ${URL_ARRAY[${i}]}echo "saved as ${NAME_ARRAY[${i}]}" curl ${URL_ARRAY[${i}]} -o images/${NAME_ARRAY[${i}]}sleep 1done

In the above example, we hope that you can use the following features :-)

Created by long Luo at 22:44:52 @ Shenzhen, China.
Completed by long Luo at 23:01:05 @ Shenzhen, China.



A shell script for batch download of network images

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.