Bash to check SSL cert expired

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: >/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))/(**)))
echo "day left:"$DAYS_LEFT
# if [ $DAYS_LEFT -ge -a $DAYS_LEFT -lt ];
# 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
上一篇:C# this扩展方法


下一篇:c#扩展方法-摘自msdn