#!/bin/bash
#Program:

#    This program is designed to download the Whole Web Server of photoshops as much as it can do.
#      GNU Wget is a free utility for non-interactive download of files from the Web.
#      It supports HTTP, HTTPS, and FTP protocols, as well as retrieval through HTTP proxies.
#date: 2014/11/13 20:13      Author:    zcy

#

#由于这里存在一些版权的问题<Copyright>,故将以下内容更改,但结构没有变化

declare -a unit=('WINDOWS' 'NETWORK' 'CISCO' 'SYSTEM01' 'SYSTEM02' 'SERVICES01' 'SERVICES02' 'SEQ SERVER' 'SHELL' 'OPERATION' 'MONITOR' 'SECURITY' 'CLUSTER' 'TUNING' )
declare -a DAY=(‘D01’'D02' 'D03' 'D04' 'D05' 'D06' 'D07' 'D08')
cu=XXXXXX
p=XXXXXXXXXXXXXXXXX
fp=XXXXXXXXXXXXXXX

 

#借助多次遍历有效实现递归,划分层次
#wget一旦使用-O选项对下载后的文件进行改名,即使存在404(Not Found)错误,也会创建为一个空文件,这一点要注意,于是才有了下述的删除过程
#
for i in ${unit[@]}
do
     mkdir $i    

     cd $i
     for j in ${DAY[@]

     do

            mkdir $j

            cd $j

            for x in `seq 80`

            do

                    if [ "$x" -le 9 ];then

                            wget -q  $p$i'/'$j'/'$cu$fp$i$j'_''00'$x.png -O $i'_''00'$x.png

                    else

                            wget -q  $p$i'/'$j'/'$cu$fp$i$j'_''0'$x.png -O $i'_''0'$x.png

                    fi

           done

           for r in $(ls -l  | awk '{if($5==0){print $NF}}')  #在下载完成的同时进行检验,删除无效的文件

                                                                            #别名alias在脚本里无效,需使用ls -l

          do

                    rm -rf ./$r
          done

          cd ../ && echo "The $i$j is OK !"

    done

    rmdir  ./*  &> /dev/null #由于之前的第一次删选,在此结果上就会存在空目录,这里将空目录进行删除

    cd ../  && echo "The $i$j is OK !"
done