方法一:
#!/bin/bash #Author: Yang YuanQiang #Blog1: http://aqiang.blog.51cto.com #Blog2: http://www.cnblogs.com/ivan-yang/ #Time: 2018-01-24 13:50:53 #Name: day13_20180124.sh #Version: V1.0 #Description: This is a script. echo "Useage $0 域名,如: $0 baidu.com" if [ $# -ne 1 ] then exit fi which whois > /dev/null 2> /dev/null if [ $? -ne 0 ] then yum install -y whois fi domain_date=`whois $1 |grep "Expiry Date"|awk ‘{print $4}‘|cut -d ‘T‘ -f 1` today=`date "+%F"` expiry_date=`date -d "7 day ago ${domain_date}" +%F` if [ ${expiry_date} == ${today} ] then echo "$1 域名一周后到期,请及时续费,保证网站正常访问" |mail -s "$1 域名到期通知" test@163.com fi
方法二:
#!/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_2_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 } 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 域名一周后"到期,请及时续费,保证网站正常访问" |mail -s "$1 域名到期通知" test@163.com" fi } is_install_whois notify pengqi.club