您的位置:首页 > 运维架构 > Shell

shell递归下载repo网站文件

2016-04-14 13:16 603 查看
#!/bin/bash
# ----------------------------------------------------------------
# Filename:       recursive_down_repo.sh
# Revision:       1.0
# Date:           2016-04-14
# Author:         Seth
# Email:          seth@9ishell.com
# website:        www.9ishell.com
# Description:    递归下载repo网站文件
# ----------------------------------------------------------------

bashPath="http://mirrors.aliyun.com/aliyunlinux/15.01/os/x86_64/"
bashDownPath="/opt/aliyunlinux/15.01/oss/x86_64/"
if [ ! -d $bashdownpath ]; then
mkdir -p $bashdownpath
fi
function recursive_down()
{
echo "当前网址路径:"$1
list=`curl $1 | grep href  | awk -F '"' '{print $2}' | grep -v "^\."`
for l in $list
do
full=$1$l
#判断是否为目录,为目录则递归调用
#获得下载路径
downPath=`echo $full | sed "s#$bashPath#$bashDownPath#"`
if [[ $l =~ "/" ]]
then
#递归调用
recursive_down "$full"
else
#创建下载目录
if [ ! -d $downPath ]; then
mkdir -p $downPath
fi
#获取文件名
filename=$(basename "$full")
#判断是否存在文件,不存在即下载
if [ ! -f "$downPath$filename" ];then
echo "正在下载$full 到 $downPath"
wget $full -P $downPath
fi
fi
done

}
recursive_down $bashPath
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: