当前位置:网站首页>检测证书过期脚本
检测证书过期脚本
2020-11-06 21:29:00 【程序猿欧文】
前提
总是后知后觉,总是后知后觉。目前的现状是不论出现什么问题,都无法进行提前预警和在客户未知前介入处理。早上偶然和研发经理交流时突发灵感,写下此脚本,试图以此为开始进行提前的预警。
从生产k8s集群拿到realibox.cn的证书,在预发环境做daemon案例。
daemon案例
# pwd/yufa/zhengshu/testlltotal 32-rw-r--r-- 1 root wheel 465B 9 9 09:50 test-ingress.yaml-rw-r--r-- 1 root wheel 711B 9 9 09:47 test.yaml-rw-r--r-- 1 root wheel 3.5K 9 9 09:24 tls.crt-rw-r--r-- 1 root wheel 1.6K 9 9 09:25 tls.key# kubectl -n realibox create secret tls realibox-cn --key ./tls.key --cert ./tls.crt# cat test.yamlapiVersion: v1kind: Servicemetadata: name: tomcat namespace: realiboxspec: selector: app: tomcat release: canary ports: - name: http port: 8080 targetPort: 8080 - name: ajp port: 8009 targetPort: 8009---apiVersion: apps/v1kind: Deploymentmetadata: name: tomcat-deploy namespace: realiboxspec: replicas: 1 selector: matchLabels: app: tomcat release: canary template: metadata: labels: app: tomcat release: canary spec: containers: - name: tomcat image: tomcat:7-alpine ports: - name: httpd containerPort: 8080 - name: ajp containerPort: 8009# cat test-ingress.yamlapiVersion: extensions/v1beta1kind: Ingressmetadata: name: ingress-tomcat-tls namespace: realibox annotations: kubernets.io/ingress.class: "kong"spec: tls: - hosts: - "*.realibox.cn" #与secret证书的域名需要保持一致 secretName: realibox-cn #secret证书的名称 rules: - host: zisefeizhu.realibox.cn http: paths: - path: backend: serviceName: tomcat servicePort: 8080

编写检测域名过期小脚本
话不多说直接怼脚本
# cat check_daemon.sh#!/bin/bashsource /etc/profile#定义邮件发送列表maillist=( linkun@realibox.com #2350835860@qq.com)#发送邮件函数send_mail(){ SUBJECT="$1域名即将到期" if [ $2 -ge 0 ];then CONTENT="$1:此域名即将到期,剩余时间已不足$2天,请及时续期!" for mail in ${maillist[*]};do echo -e ""当前检测的域名:" $domain\n "剩余天数: " $days\n ${CONTENT} " | mail -s "${SUBJECT}" $mail done else day=$((-$2)) CONTENT="$1:此域名已到期,已超出$day天,请及时续费!" for mail in ${maillist[*]};do echo -e "${CONTENT}" | mail -s "${SUBJECT}" $mail done fi}#检测mails命令是否存在,不存在则安装mail包is_install_mail(){ which mail &> /dev/null if [ $? -ne 0 ];then yum install -y mail fi}is_install_mail#定义需要被检测的域名列表domainlist=( zisefeizhu.realibox.cn)#检测域名到期时间并通知for domain in ${domainlist[*]};do echo "当前检测的域名:" $domain #取出域名过期时间 end_time=$(echo | timeout 1 openssl s_client -servername $domain -connect $domain:443 2>/dev/null | openssl x509 -noout -enddate 2>/dev/null | awk -F '=' '{print $2}' ) ([ $? -ne 0 ] || [[ $end_time == '' ]]) && exit 10 end_times=`date -d "$end_time" +%s ` tmp=`date -d today +"%Y-%m-%d %T"` current_times=`date -d "$tmp" +"%s"` let left_time=$end_times-$current_times days=`expr $left_time / 86400` echo "剩余天数: " $days #转换成时间戳 end_times=`date -d "$end_time" +%s ` #以时间戳的形式显示当前时间 tmp=`date -d today +"%Y-%m-%d %T"` current_times=`date -d "$tmp" +"%s"` #域名到期剩余天数 let left_time=$end_times-$current_times days=`expr $left_time / 86400` echo "剩余天数: " $days if .........
版权声明
本文为[程序猿欧文]所创,转载请带上原文链接,感谢
https://my.oschina.net/mikeowen/blog/4555139
边栏推荐
- The dynamic thread pool in Kitty supports Nacos and Apollo multi configuration centers
- What are PLC Analog input and digital input
- Interface pressure test: installation, use and instruction of siege pressure test
- 快速排序为什么这么快?
- Advanced Vue component pattern (3)
- html+vue.js 實現分頁可相容IE
- What knowledge do Python automated testing learn?
- How to understand Python iterators and generators?
- What are manufacturing and new automation technologies?
- Network programming NiO: Bio and NiO
猜你喜欢

2020年第四届中国 BIM (数字建造)经理高峰论坛即将在杭举办

用一个例子理解JS函数的底层处理机制

新建一个空文件占用多少磁盘空间?

The road of C + + Learning: from introduction to mastery
![Network security engineer Demo: the original * * is to get your computer administrator rights! [maintain]](/img/14/ede1ffa7811dbc2a5b15b9a7b17a5e.jpg)
Network security engineer Demo: the original * * is to get your computer administrator rights! [maintain]

小游戏云开发入门

大道至简 html + js 实现最朴实的小游戏俄罗斯方块

DRF JWT authentication module and self customization

【字节跳动 秋招岗位开放啦】Ohayoo!放学别走,我想约你做游戏!!!

快速排序为什么这么快?
随机推荐
Xmppmini project details: step by step from the principle of practical XMPP technology development 4. String decoding secrets and message package
Multi classification of unbalanced text using AWS sagemaker blazingtext
TensorFlow中的Tensor是什么?
2020年第四届中国 BIM (数字建造)经理高峰论坛即将在杭举办
Use modelarts quickly, zero base white can also play AI!
Three Python tips for reading, creating and running multiple files
Read the advantages of Wi Fi 6 over Wi Fi 5 in 3 minutes
如何在终端启动Coda 2中隐藏的首选项?
Analysis of ThreadLocal principle
Introduction to Google software testing
開源一套極簡的前後端分離專案腳手架
Gather in Beijing! The countdown to openi 2020
大道至简 html + js 实现最朴实的小游戏俄罗斯方块
Shh! Is this really good for asynchronous events?
Recommendation system based on deep learning
What are the common problems of DTU connection
Isn't data product just a report? absolutely wrong! There are university questions in this category
这个项目可以让你在几分钟快速了解某个编程语言
Analysis of etcd core mechanism
Individual annual work summary and 2019 work plan (Internet)