检查域名过期

思路

* whois命令过滤到期时间
  · 判断whois命令是否存在  which  whois ;$?
* 时间格式转换
  · 转换为秒级  date +%s  -d '过滤的时间'
  · 当前时间的转换
* 两个时间相减
  · echo  s1 - s2 |bc
* 相差时间格式的转换
  · /60/60/24  天
* 输出打印
* 多个网址判断  for  do  done

脚本

#!/bin/bash
#1.检查用户
#2.检查参数
domains="$*"
function check_param(){
        [ -z "$domains" ]&&{
           echo "Usage:$0 + web"
           exit 1
        }
}
#3.检查命令
function check_cmd(){
        if  ! which whois >/dev/null 2>&1;then
                echo "命令不存在请安装"
                echo "红帽类系统jwhois,其他系统whois"
                exit 1
        fi
}
#3.判断过期
function check_domain_expire(){
for domain in $domains
do
        #过期日期
  domain_expire_date=`whois $domain |egrep -i "(Expiry|Expiration) (Date|Time)" |awk -F '[ T]+' '{print $(NF-1)}'`
        #过期日期转换为秒
  domain_expire_seconds=`date +%s -d "${domain_expire_date}"`
        #今日时间,秒为单位
  domain_today_seconds=`date +%s`
        #进行计算剩会的天数
        domain_expire_days=`echo "(${domain_expire_seconds} - ${domain_today_seconds})/60/60/24" |bc`
    if [ ${domain_expire_days} -le 30 ];then
        redecho "$domain将要过期:还有${domain_expire_days}"
    else
        greenecho "$domain 还没有过期,还有${domain_expire_days}"
    fi
done

}
main(){
check_param
check_cmd
check_domain_expire
}
main
posted @ 2024-09-29 21:28  kyle_7Qc  阅读(45)  评论(0)    收藏  举报