0%

shell-check-domain-ssl

检查域名SSL证书到期时间

1、准备域名列表

1
2
3
4
5
6
#domain.txt

www.zhaohongye.com
www.virgo.pub
www.ops.work
wwww.ops.ren

2、Shell脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/bash

readFile="domain.txt"

#读取域名信息
grep -v '^#' ${readFile} | while read line;do
# get_domain=$(echo "${line}" | awk -F ':' '{print $1}')
get_domain=${line}
port=443
# 检测端口是否可以telnet
result=`echo ""|telnet ${line} 443 2>/dev/null|grep "\^]"|wc -l`

if [[ ${result} -eq 1 ]];then
END_TIME=$(echo | openssl s_client -servername ${get_domain} -connect ${get_domain}:${port} 2>/dev/null | openssl x509 -noout -dates |grep 'After'| awk -F '=' '{print $2}'| awk -F ' +' '{print $1,$2,$4 }' )
echo "${get_domain} : ${END_TIME}"
fi
done

3、返回结果

1
2
3
4
5
6
7
8
9
#sh check_ssl.sh

www.zhaohongye.com : Apr 7 2022
www.virgo.pub : Nov 9 2022
www.ops.work : Nov 9 2022
wwww.ops.ren : Nov 9 2022
www.vuedemo.cn : Nov 9 2022
crm.ops.work : Oct 22 2022
api.ops.work : Oct 22 2022