zoukankan      html  css  js  c++  java
  • 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 "
     Correct ZIP passwd : ${pass}"
                echo "${DATEFULL}    Unzip password is correct:[Unzip right]        passwd:${pass}" >> ${LOGPATH}/hosts.log
                echo "Unzip done!!!"
                
            else
                echo -e  "
    Unzip  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
  • 相关阅读:
    Ajax 导出Excel 方式
    配置文件类型
    Ionic 发布Release 版本
    $cordovaNetwork 使用
    Web Api 跨域问题
    Python学习(五)--字典
    Python学习(四)--字符串
    Python学习(三)--列表和元组
    mac下安装HTMLTestRunner
    mac下selenium+python环境搭建
  • 原文地址:https://www.cnblogs.com/zhuandshao/p/7413609.html
Copyright © 2011-2022 走看看