阿铭每日一题 day 13 20180124

Posted Ivan_yyq

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了阿铭每日一题 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

 

以上是关于阿铭每日一题 day 13 20180124的主要内容,如果未能解决你的问题,请参考以下文章

阿铭每日一题 day 1 20180111

阿铭每日一题 day 7 20180117

阿铭每日一题 day 3 20180113

阿铭每日一题 day 8 20180118

阿铭每日一题 day 5 20180115

阿铭每日一题 day 6 20180116