• 阿铭每日一题 day 13 20180124


    方法一:

    #!/bin/bash
    #Author: Yang YuanQiang
    #Blog1: http://aqiang.blog.51cto.com
    #Blog2: http://www.cnblogs.com/ivan-yang/
    #Time: 2018-01-24 17:05:09
    #Name: day13_20180124.sh
    #Version: V1.0
    #Description: This is a script.
    
    t1=`date +%s`
    is_install_whois()
    {
        which whois > /dev/null 2> /dev/null
        if [ $? -ne 0 ]
        then
            yum install -y whois
        fi
    }
    
    is_install_bc()
    {
        which bc > /dev/null 2> /dev/null
        if [ $? -ne 0 ]
        then
            yum install -y bc
        fi
    }
    
    notify()
    {
        e_d=`whois $1 | grep "Expiry Date" |awk '{print $4}' |cut -d 'T' -f 1`
        e_t=`date -d "$e_d" +%s`
        n=`echo "86400*7"|bc`
        e_t1=$[$e_t-$n]
        if [ $t1 -ge $e_t1 ] && [ $t1 -lt $e_t ]
        then
            echo "$1 域名在${e_d}到期,请及时续费,保证网站正常访问" |mail -s "$1 域名到期通知" aming_test@163.com
        fi
    }
    
    is_install_whois
    is_install_bc
    notify aminglinux.com

    方法二:

    #!/bin/bash
    #Author: Yang YuanQiang
    #Blog1: http://aqiang.blog.51cto.com
    #Blog2: http://www.cnblogs.com/ivan-yang/
    #Time: 2018-01-24 17:10:09
    #Name: day13_2_20180124.sh
    #Version: V1.0
    #Description: This is a script.
    
    
    t1=`date +%s`
    which whois > /dev/null 2> /dev/null
    if [ $? -ne 0 ]
    then
        yum install -y whois
    fi
    
    which bc > /dev/null 2> /dev/null
    if [ $? -ne 0 ]
    then
        yum install -y bc
    fi
    cat domain.txt |while read line
    do
        domain_date=`whois ${line} |grep "Registry Expiry Date" |awk '{print $4}' |cut -d 'T' -f 1`
        domain_time=`date -d "${domain_date}" +%s`
        n=`echo "86400*7|bc"`
        domain_time1=$[$domain_time - $n]
        if [ $t1 -ge $domain_time1 ] && [ $t1 -lt $domain_time ]
        thenecho "$1 域名在 $domain_date 到期,请及时处理。" |mail -s "$1 域名到期通知" aming_test@163.com
        fi
    done

     == day 13参考答案 ==

    #!/bin/bash
    t1=`date +%s`
    is_install_whois()
    {
        which whois >/dev/null 2>/dev/null
        if [ $? -ne 0 ]
        then
            yum install -y jwhois
        fi
    }
    notify()
    {
        e_d=`whois $1|grep 'Expiry Date'|awk '{print $4}'|cut -d 'T' -f 1`
        e_t=`date -d "$e_d" +%s`
        n=`echo "86400*7"|bc`
        e_t1=$[$e_t-$n]
        if [ $t1 -ge $e_t1 ] && [ $t1 -lt $e_t ]
        then
            /usr/local/sbin/mail2.py aming_test@163.com "Domain $1 will be expire." "Domain $1 expire date is $e_d."
        fi
    }
    is_install_whois
    notify aminglinux.com
  • 相关阅读:
    Ximarin.Android 百度地图
    利用Chrome浏览器 保存网页成PDF
    SQL 笔记
    windows server 2008 r2 IIS PHP
    自动化分页,HTML代码控制 思想
    simple
    testtitle
    PyQt5中中文问题的不完全解决
    ubuntu下搭建python2.7+PyQt5并实现一个小词典
    opensuse安装深度截图,深度影音和深度播放器
  • 原文地址:https://www.cnblogs.com/ivan-yang/p/8342705.html
Copyright © 2020-2023  润新知