域名ssl证书到期飞书提醒

#!/bin/sh

#set -x

alert_threshold=5

now_date=date +%s
echo $now_date
while read name
do
expdata=curl -v -s --connect-timeout 3 https://$name 2>&1 |grep "expire date" | sed 's/expire date://'|sed 's/\*//' |sed 's/GMT//'
echo $name $expdata >/opt/check_ssl/exp.txt

#month=echo $expdata |awk '{print $1}' |grep -o '[0-9]'

month=echo $expdata |awk '{print $1}'
case ${month} in
“Jan”) month=1;;
“Feb”) month=2;;
“Mar”) month=3;;
“Apr”) month=4;;
“May”) month=5;;
“Jun”) month=6;;
“Jul”) month=7;;
“Aug”) month=8;;
“Sep”) month=9;;
“Oct”) month=10;;
“Nov”) month=11;;
“Dec”) month=12;;
esac
echo “——————-“
echo ${month}
day=echo $expdata |awk '{print $2}'
year=echo $expdata |awk '{print $NF}'
if [[ $month -lt 9 ]];then
exp_date=$year-0$month-$day
else
exp_date=$year-$month-$day
fi
#echo $exp_date
utc_exp_date=date -d "$exp_date" +%s
echo $utc_exp_date
diff_values_s=expr $utc_exp_date - $now_date
diff_values_day=expr $diff_values_s / 3600 / 24
echo $diff_values_day

if [[ $diff_values_day -lt ${alert_threshold} ]];then
echo $name ssl auth less $diff_values_day.
echo “———————————————“
msg=”$name ssl auth less $diff_values_day.”
# cd /opt/check_ssl && sh feishu.sh ${msg}

url=”https://open.feishu.cn/open-apis/bot/v2/hook/ae8efb0b-7f7e-4f39-9891-3465fdcfcfa2″
data=$(jq -nc ‘{“msg_type”: “text”,”content”: {“text”: “‘”${msg}”‘”}}’)

curl -X POST -H ‘Content-Type: application/json’ -d “$data” “$url”

fi

done </opt/check_ssl/do_name.txt

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注