首页 > 系统服务 > 详细

Shell脚本实现批量下载资源并保留原始路径

时间:2017-11-10 17:46:20      阅读:289      评论:0      收藏:0      [点我收藏+]

示例资源列表
如url.txt:

http://su.bdimg.com/static/superplus/img/logo_white_ee663702.png
http://su.bdimg.com/static/superplus/img/logo_white_ee663703.png
http://su.bdimg.com/static/superplus/img/logo_white_ee663701.png
http://su.bdimg.com/static/superplus/img/logo_white_ee663704.png
http://su.bdimg.com/static/superplus/img/logo_white_ee663705.png
http://su.bdimg.com/static/superplus/img/logo_white_ee663706.png

脚本如下:

download.sh

#!/bin/bash
# desc: download resource
# author: John

mydir=`pwd`

while read line
do
{
    if [ -n "$line" ]
    then
        cd $mydir
        url=$(echo "$line" | tr -d \r)
        picdir=$(echo $url | sed -r s/http:\/\///g)
        picname=$(echo ${picdir##*/})
        picpath=$(echo ${picdir%/*})
        mkdir -p $picpath
        cd $picpath
        wget -O $picname `echo $url`
    fi
}
done < $1
exit 0

运行:

sh download.sh url.txt

 

Shell脚本实现批量下载资源并保留原始路径

原文:http://www.cnblogs.com/John-2011/p/7815509.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!