Bash to check SSL cert expired

谭琛
2023-12-01

Code like this, You can send out a email to notice

$ cat urls.txt 
www.baidu.com

$ cat cert_chk.sh 
#!/bin/bash 
for url in `cat ./urls.txt`
do
 END_TIME=$(echo | openssl s_client -servername $url -connect $url:443 2>/dev/null | openssl x509 -noout -dates |grep 'After'| awk -F '=' '{print $2}'| awk -F ' +' '{print $1,$2,$4 }' )
 echo "$END_TIME $url"
 END_TIME1=$(date +%s -d "$END_TIME")
 NOW_TIME=$(date +%s -d "$(date | awk -F ' +'  '{print $2,$3,$6}')")
 DAYS_LEFT=$(($(($END_TIME1-$NOW_TIME))/(60*60*24)))
 echo "day left:"$DAYS_LEFT
# if [ $DAYS_LEFT -ge 0 -a $DAYS_LEFT -lt 15 ];
# then
#   echo "Please be advised, site $url - cert will expire in $DAYS_LEFT days ($END_TIME)" | mailx -s 'Cert Expiration Notification' -aFrom:no-reply abc@abc.com
# fi
done

 

转载于:https://www.cnblogs.com/oskb/p/10238996.html

 类似资料:

相关阅读

相关文章

相关问答