Shell 镜像repo站点脚本

#!/bin/bash
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

转载至:https://blog.csdn.net/bwlab/article/details/51150801