shell小脚本--从laod博客更新hosts文件

#!/bin/bash
#--------------------------------------------
#             name: change-hosts.sh            
#--------------------------------------------
#--------------------------------------------
#Program:
#
#    从laod博客更新hosts文件
#
#--------------------------------------------
#--------------------------------------------
#History:
#    2017/08/20    qi    1.0  
#--------------------------------------------
#--------------------------------------------

PATH=/bin:/sbin:/usr/bin:/usr/sbin:usr/local/bin:usr/local/sbin:~/bin
export PATH

DATE=`date +%Y%m%d`
DATEFULL=`date`

URL="https://iiio.io/download/${DATE}/Android安卓跟Linux系列.zip"

LOGPATH=/home/qi/log

DOWNPATH=/home/qi/download/hosts

PASSWD=("blog" "laod" "google")

echo ${PASSWD[*]}
#下载hosts文件到download文件夹;如果已经存在,将不会下载
if test -e ${DOWNPATH}/Android安卓跟Linux系列.zip  
then
    echo "The zip is exists"
else
    echo "Downloading ......"
    wget ${URL} -P ${DOWNPATH} || {
        echo "${DATEFULL}    ${URL}:[URL error] " >> ${LOGPATH}/hosts.log
        exit 1
}
fi

#判断下载的文件是否正确,若正确,解压缩;否则计入日志。
if test -e ${DOWNPATH}/Android安卓跟Linux系列.zip  
then
    mkdir ${DOWNPATH}/${DATE}

    echo "Unzip doing ......"
    for pass in ${PASSWD[*]}
    do
        echo $pass
        unzip -P ${pass}  -d ${DOWNPATH}/${DATE}/ ${DOWNPATH}/Android安卓跟Linux系列.zip  

        # code 82 : password not correct
        if [ -f ${DOWNPATH}/${DATE}/hosts ]
        then
            echo -e "\n Correct ZIP passwd : ${pass}"
            echo "${DATEFULL}    Unzip password is correct:[Unzip right]        passwd:${pass}" >> ${LOGPATH}/hosts.log
            echo "Unzip done!!!"
            
        else
            echo -e  "\nUnzip  password error"
            echo "${DATEFULL}    Unzip password not correct:[Unzip error]     wrong pass:${pass}" >> ${LOGPATH}/host.log
        fi
    done

    echo
    
    echo "Coping ......"
    sudo cp -f ${DOWNPATH}/${DATE}/hosts /etc/ || {
        echo "${DATEFULL}    hosts file can not be copied successfully!!!" >> ${LOGPATH}/hosts.log
        exit 2
    }
    echo

    echo "Copy hosts to /etc success!!!"
    echo

    rm -rf ${DOWNPATH}/*.zip
    echo "Clean Over !!!"

    exit 0
else
    echo "${DATE}    hosts file not exists!!!" >> ${LOGPATH}/hosts.log
    exit 3
fi

 

转载于:https://www.cnblogs.com/zhuandshao/p/7413609.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值