Uninote
Uninote
  • 脚本所在服务器 116.62.117.165
  • 定时任务示例 0 09 * * * root /bin/bash /server/sslcheck/sslcheck.sh > /dev/null 2>&1
  • 检查域名的证书是否到期
#!/bin/bash
prefix="dev. pre. t1."
content="www. api. staffapi. m. admin."
domain="dajxyl.com"
days=20
offtime=`echo $[$days*24*3600]`
nowtime=`date +%s`
declare -i count
for i in "" $prefix;do
  for j in $content;do
   echo "Check $i$j$domain"
    echo | openssl s_client -servername $i$j$domain -connect $i$j$domain:443 2>/dev/null | openssl x509 -noout -dates > /dev/null 2>&1
    [ $? -ne 0 ] && echo Error no ssl && continue
    resulttimedate=`echo | openssl s_client -servername $i$j$domain -connect $i$j$domain:443 2>/dev/null | openssl x509 -noout -enddate|awk -F "=" '{print $2}'`
    resulttimedatetime=`date +%s -d "$resulttimedate"`
    resulttime=`echo $[ $resulttimedatetime -$nowtime ]`
    echo | openssl s_client -servername $i$j$domain -connect $i$j$domain:443 2>/dev/null | openssl x509 -noout -checkend $offtime
    result=`echo $?`
    if [ $result -eq 1 ];then
      message=`echo -e "$i$j$domain, expires time: $(echo $[$resulttime/3600/24]) < $days (day)"`
      resultarray[$count]="$message"
    fi
    let count++
  done
done
echo '++++++++++'
echo 'result:'
for i in "${resultarray[@]}";do
  if [ ! -z "$i" ];then
     echo -e "$i"
  fi
done
echo '----------'
ddMessage=`echo -e "${resultarray[@]}"`
[ ! -z $ddMessage ] && curl 'https://oapi.dingtalk.com/robot/send?access_token=1c54eb9b30319b136fe5ddd1d7d59f20e062d8bf89cb3bc2a4627c537be01c60' \
   -H 'Content-Type: application/json' \
   -d "{\"msgtype\": \"text\",
    \"text\": {\"content\": \"脚本推送-证书检查: $ddMessage\"}}"

shellscripts在线格式化

centos6.x系统yum源问题

点赞(0) 阅读(1) 举报
目录
标题