LiuYuan's Blog
This is LiuYuan's Blog
Toggle navigation
LiuYuan's Blog
Home
Docker相关
MySQL相关
Ansible相关
维护脚本相关
Windows系统脚本
Python相关
Nginx相关
About Me
Archives
Tags
SSL证书监控脚本
2024-06-19 16:04:41
71
0
0
admin
#!/bin/bash # 域名列表 domains=("www.qq.com" "www.qq.com.cn" "www.ww.cn") #查询/etc/nginx/conf.d/*.conf配置文件中的域名,并去重,sh不支持数组,如果用这种方式 需要bash环境运行 #domains=($(grep -hroP 'server_name\s+\K\S+' /etc/nginx/conf.d/*.conf | tr -d ';' | sort -u)) # 企业微信群聊机器人的 Webhook 地址 webhook_url="https://123/123" # 循环遍历域名列表 for domain in "${domains[@]}"; do echo "$domain" # 查询域名的证书有效期 expiration_date=$(openssl s_client -connect "$domain":443 -servername "$domain" 2>/dev/null | openssl x509 -noout -dates | grep notAfter | cut -d "=" -f 2) echo "Certificate expiration for $domain: $expiration_date" # 将日期转换为时间戳 expiration_timestamp=$(date -d "$expiration_date" +%s) # 当前时间戳 current_timestamp=$(date +%s) # 计算剩余天数 remaining_days=$(( (expiration_timestamp - current_timestamp) / 86400 )) # 如果剩余天数小于等于10天,则发送警告消息到企业微信群聊机器人 if [ $remaining_days -le 10 ]; then subject="SSL Certificate Expiration Warning - $domain" message="The SSL certificate for $domain will expire in $remaining_days days." # 发送消息到企业微信群聊机器人 curl -s -H "Content-Type: application/json" -X POST "$webhook_url" \ -d '{ "msgtype": "text", "text": { "content": "'"$message"'" } }' echo "Sent SSL certificate expiration warning for $domain." fi done
Pre: No Post
Next:
命令备忘
0
likes
71
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Footer
Table of content