1.以下是脚本内容:
备注:脚本是我好哥们写的,我只是用于个人收藏

check_ssl.sh内容为 ,里面会下载一个测试脚本,并创建软连接

#!/bin/bash
###证书到期检测
#author 阿南

script_dir=$( cd $(dirname "$0") && pwd )

which ssl-cert-check >>/dev/null

if [ $? -ne 0 ];then wget -P ${script_dir}/ssl-check https://raw.githubusercontent.com/Matty9191/ssl-cert-check/master/ssl-cert-check  && cd ${script_dir}/ssl-check/ && chmod +x ssl-cert-check && ln -s ${script_dir}/ssl-check/ssl-cert-check /usr/bin/ ;fi

cat ${script_dir}/domain_ssl.info >>/dev/null

if [ $? -ne 0 ];then find / -name domain_ssl.info -exec \cp -rf {} ${script_dir}/ \; ;fi

cat ${script_dir}/domain_ssl.info >> /dev/null 

if [ $? -eq 0 ];then  echo -e 检测时间: $(date +'%Y-%m-%d  %R') > ${script_dir}/jc.txt  && echo -e "\n " >> ${script_dir}/jc.txt ;fi 

cat ${script_dir}/domain_ssl.info |while read line;do

ssl-cert-check -i -s ${line} -p 443 >>${script_dir}/未过滤.txt

done

#开始过滤

egrep '(-[0-9]{4,10})' ${script_dir}/未过滤.txt  |awk '{print $1}' > ${script_dir}/被墙或没有证书 && sed -i "s#:443##g" ${script_dir}/被墙或没有证书 

egrep 'Unable' ${script_dir}/未过滤.txt |awk '{print $1}' > ${script_dir}/没有dns解析 && sed -i "s#:443##g" ${script_dir}/没有dns解析

egrep '(ERROR)' ${script_dir}/未过滤.txt |egrep '(for)' |awk '{print $10}' > ${script_dir}/无法正常访问 && sed -i "s#:443##g" ${script_dir}/无法正常访问

egrep -v '(-[0-9]{4,10}|Unable|ERROR)' ${script_dir}/未过滤.txt  | egrep '([0-9]{1,4})'| awk  ' {print "域名"$1,"证书剩余过期天数"$8" 天"}' >> ${script_dir}/jc.txt && sed -i "s#:443##g" ${script_dir}/jc.txt


n1=`wc -l ${script_dir}/jc.txt |awk '{print $1}'`
n2=4

head -`expr ${n1} - ${n2}` ${script_dir}/jc.txt | while read line;do

   number=` echo $line |awk '{print $2}' |egrep -o '([0-9]{1,3})'`
   if [ $number -lt 20 ];then echo  " ${line}" >> $script_dir/zjjc.txt;fi
done


sh ${script_dir}/message.sh

2.然后需要创建一个domain_ssl.info文件,用于存放域名,格式为一行一个:

wohenliu.com 
www.wohenliu.com 
www.wohenliu.com
baidu.com 
baidu.com 
taobao.com
  1. 写个发信息的脚本,message.sh 在这里需要自己先申请个telegram机器人,获取api接口信息,可以参考我之前的文章
#!/bin/bash

script_dir=$( cd $(dirname "$0") && pwd )

line=`wc -l ${script_dir}/jc.txt | awk '{ print $1}'`

sed -i '2i\以下为域名证书到期时间' ${script_dir}/zjjc.txt

if [ $line -gt 1 ];then

curl -X POST "https://api.telegram.org/bot709759784:AAF2Tff_lKOBLIXHPzfoM1WHQkXt-SqkAqo/sendMessage" -d "chat_id=-377237859&text=`head -100 ${script_dir}/zjjc.txt`"

fi


if [ $line -gt 100 ];then

curl -X POST "https://api.telegram.org/bot709759784:AAF2Tff_lKOBLIXHPzfoM1WHQkXt-SqkAqo/sendMessage" -d "chat_id=-377237859&text=`sed -n '101,200p' ${script_dir}/zjjc.txt`"

fi

if [ $line -gt 200 ];then

curl -X POST "https://api.telegram.org/bot709759784:AAF2Tff_lKOBLIXHPzfoM1WHQkXt-SqkAqo/sendMessage" -d "chat_id=-377237859&text=`sed -n '201,300p' ${script_dir}/zjjc.txt`"


fi

if [ $line -gt 300 ];then

curl -X POST "https://api.telegram.org/bot709759784:AAF2Tff_lKOBLIXHPzfoM1WHQkXt-SqkAqo/sendMessage" -d "chat_id=-377237859&text=`sed -n '301,400p' ${script_dir}/zjjc.txt`"

fi

if [ $line -gt 400 ];then

curl -X POST "https://api.telegram.org/bot709759784:AAF2Tff_lKOBLIXHPzfoM1WHQkXt-SqkAqo/sendMessage" -d "chat_id=-377237859&text=`sed -n '401,500p' ${script_dir}/zjjc.txt`"

fi

if [ $line -gt 500 ];then

curl -X POST "https://api.telegram.org/bot709759784:AAF2Tff_lKOBLIXHPzfoM1WHQkXt-SqkAqo/sendMessage" -d "chat_id=-377237859&text=`sed -n '501,600p' ${script_dir}/zjjc.txt`"

fi

if [ $line -gt 600 ];then

curl -X POST "https://api.telegram.org/bot709759784:AAF2Tff_lKOBLIXHPzfoM1WHQkXt-SqkAqo/sendMessage" -d "chat_id=-377237859&text=`sed -n '601,700p' ${script_dir}/zjjc.txt`"

fi

if [ $line -gt 700 ];then

curl -X POST "https://api.telegram.org/bot709759784:AAF2Tff_lKOBLIXHPzfoM1WHQkXt-SqkAqo/sendMessage" -d "chat_id=-377237859&text=`sed -n '701,800p' ${script_dir}/zjjc.txt`"

fi

if [ $line -gt 800 ];then

curl -X POST "https://api.telegram.org/bot709759784:AAF2Tff_lKOBLIXHPzfoM1WHQkXt-SqkAqo/sendMessage" -d "chat_id=-377237859&text=`sed -n '801,900p' ${script_dir}/zjjc.txt`"

fi

if [ $line -gt 900 ];then

curl -X POST "https://api.telegram.org/bot709759784:AAF2Tff_lKOBLIXHPzfoM1WHQkXt-SqkAqo/sendMessage" -d "chat_id=-377237859&text=`sed -n '901,1000p' ${script_dir}/zjjc.txt`"

fi

sed -i '1i\以下为被墙或没有证书\n' ${script_dir}/被墙或没有证书

curl -X POST "https://api.telegram.org/bot709759784:AAF2Tff_lKOBLIXHPzfoM1WHQkXt-SqkAqo/sendMessage" -d "chat_id=-377237859&text= `cat ${script_dir}/被墙或没有证书`"


sed -i '1i\以下为没有dns解析\n' ${script_dir}/没有dns解析

curl -X POST "https://api.telegram.org/bot709759784:AAF2Tff_lKOBLIXHPzfoM1WHQkXt-SqkAqo/sendMessage" -d "chat_id=-377237859&text= `cat ${script_dir}/没有dns解析`"

sed -i '1i\以下为无法正常访问\n' ${script_dir}/无法正常访问

curl -X POST "https://api.telegram.org/bot709759784:AAF2Tff_lKOBLIXHPzfoM1WHQkXt-SqkAqo/sendMessage" -d "chat_id=-377237859&text= `cat ${script_dir}/无法正常访问`"

rm -rf ${script_dir}/未过滤.txt  
rm -rf ${script_dir}/被墙或没有证书 
rm -rf ${script_dir}/zjjc.txt 
rm -rf ${script_dir}/无法正常访问 
rm -rf ${script_dir}/jc.txt 
rm -rf ${script_dir}/没有dns解析 



4.脚本动弄好之后,就要设置定时任务,设置每天8点执行一次

crontab   -e
00 8 * * * sh /check-ssl/check_ssl.sh

注意,第一个脚本执行需要先按装wget

Last modification:January 16th, 2020 at 07:10 pm
如果觉得我的文章对你有用,请随意赞赏