curl递归下载软件shell脚本

发布时间:2020-12-23编辑:脚本学堂
分享一例shell脚本,curl递归下载软件,对apache的镜像网站的递归扫描。通过文件io的缓存方式记录可下载文件,再针对需要文件的后缀名批量下载软件包备用。

例子,curl递归下载软件的shell/ target=_blank class=infotextkey>shell脚本

代码:
 

复制代码 代码示例:
#!/bin/env bash
path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export path
clear
url="http://mirrors.cnnic.cn/apache/"
downlistfile="/tmp/downlist.txt"
downlisttmpfile="/tmp/tmplist.txt"
downfiletype="zip$|gz$"
downlist=""
urlback="$url"
[ ! -f $downlistfile ] && touch $downlistfile || echo > $downlistfile
[ ! -f $downlisttmpfile ] && touch $downlisttmpfile || echo > $downlisttmpfile
curl_urls(){
 urls=`curl $urlback |linuxjishu/13830.html target=_blank class=infotextkey>awk -f "a href="" '{printf "%sn",$2}'|awk -f """ '{printf "%sn",$1}'|grep -ve "^$|^?|^http://"|^#`
}
url_list(){
 curl_urls
 for i in $urls ;do
  echo "$urlback$i" >> $downlisttmpfile
 done
}
recursive_search_url(){
 urlbacktmps=`cat $downlisttmpfile`
 [[ "$urlbacktmps" == "" ]] && echo "no more page for search" && exit 1
 for j in $urlbacktmps ;do
  if [[ "${j##*/}" != "" ]] ;then
   echo "$j" >> $downlistfile
  else
   urlback="$j"
   url_list
  fi
  urltmps=`grep -ve "$j$" $downlisttmpfile`
  echo "$urltmps" > $downlisttmpfile
  recursive_search_url
 done
}
download_file(){
 downlist=`grep -e "$downfiletype" $downlistfile`
 for k in $downlist ;do
  filepath=/tmp/${k#*//}
  [ ! -d `dirname $filepath` ] && mkdir -p `dirname $filepath`
  [ ! -f $filepath ] && cd `dirname $filepath` && curl -o $k
 done
}
url_list $urls
recursive_search_url