#!/bin/bash
################ Version Info ##################
# Attention: 通过域名获取证书的过期时间
################################################
################################################
# 加载环境变量
#. /etc/profile
#. ~/.bash_profile
#. /etc/bashrc
# 脚本所在目录即脚本名称
script_dir=$( cd "$( dirname "$0" )" && pwd )
script_name=$(basename ${0})
readFile="${script_dir}/domain_ssl.info"
grep -v '^#' ${readFile} | while read line;do # 读取存储了需要监测的域名的文件
# echo "${line}"
get_domain=$(echo "${line}" | awk -F ':' '{print $1}')
get_port=$(echo "${line}" | awk -F ':' '{print $2}')
# echo ${get_domain}
# echo "${get_port}"
# echo "======"
# 使用openssl获取域名的证书情况,然后获取其中的到期时间
END_TIME=$(echo | openssl s_client -servername ${get_domain} -connect ${get_domain}:${get_port}
2>/dev/null | openssl x509 -noout
-dates |grep 'After'| awk -F '=' '{print $2}'| awk -F ' +' '{print $1,$2,$4 }' )
END_TIME1=$(date +%s -d "$END_TIME") # 将日期转化为时间戳
NOW_TIME=$(date +%s -d "$(date | awk -F ' +' '{print $2,$3,$6}')") # 将当前的日期也转化为时间戳
RST=$(($(($END_TIME1-$NOW_TIME))/(60*60*24))) # 到期时间减去目前时间再转化为天数
# echo "${get_domain}ssl过期时间还有${RST}天"
comm=30
if [ ${RST} -ge ${comm} ];then
echo "ssl正常!" >> /dev/null 2>&1 &
else
echo "${get_domain}ssl过期时间还有${RST}天" | mail -s "ssl过期告警" 754347404@qq.com
fi
done
Alkomx https://newfasttadalafil.com/ - Cialis Achat Cialis En Europe cheap cialis online pharmacy Commander Cialis Moins Cher Gmbsuu Vvskym https://newfasttadalafil.com/ - Cialis