美文网首页
监控ssl证书到期时间,并且发送钉钉通知的脚本

监控ssl证书到期时间,并且发送钉钉通知的脚本

作者: w也不知道 | 来源:发表于2019-07-16 16:03 被阅读0次
#!/bin/bash

CheckDomain="dev test pre info"
Alert_Days="15"

Check()
{
    Cur_Time=$(date +%s)
    Expire_Date=$(curl -o /dev/null -m 10 --connect-timeout 10 -svIL https://${Domain} 2>&1|grep "expire date:"|sed 's/*\s\+expire date:\s\+//')
    Expire_Time=$(date -d "${Expire_Date}" +%s)
    Alert_Time=$((${Expire_Time}-${Alert_Days}*86400))
    Expire_Date_Read=$(date -d @${Expire_Time} "+%Y-%m-%d")
    echo "Domain:${Domain} Expire Date: ${Expire_Date_Read}"

    if [ ${Cur_Time} -ge ${Alert_Time} ] ; then
        TOKEN="https://oapi.dingtalk.com/robot/send?access_token=xxx"
        DING="curl -H \"Content-Type: application/json\" -X POST --data '{\"msgtype\": \"markdown\", \"markdown\": {\"title\":\"域名ssl证书将要过期\",\"text\": \"域名:  ${Domain} 证书过期时间:  ${Expire_Date_Read}\"}}' ${TOKEN}"
    eval $DING
    fi
    sleep 1
}

for Domain in ${CheckDomain};do
    Domain=${Domain}".xxx.com"
    Check ${Domain}
done
运行结果
钉钉通知

相关文章

网友评论

      本文标题:监控ssl证书到期时间,并且发送钉钉通知的脚本

      本文链接:https://www.haomeiwen.com/subject/mrstlctx.html