shamrock@alucard:~$ cat check_ssl_expiration.sh
days=30
daystimestamp=`expr $days \* 86400`
for domain in `cat domeny.txt`
do
expire=`echo | openssl s_client -connect $domain 2>/dev/null | openssl x509 -noout -enddate | awk -F \= '{print $2}'`
out=`date -d "$expire" "+%s"`
in=`date --date="$days days" "+%s"`
res=`expr $out - $in`
if [ $res -lt 0 ]; then
echo "ALARM !!! DOMAIN $domain EXPIRED ON $expire"
elif [ $res -lt $daystimestamp ]; then
echo "ALARM !!! DOMAIN $domain WILL EXPIRE ON $expire"
else
echo "$domain WILL EXPIRE ON $expire"
fi
done
Usage:
shamrock@alucard:~$ bash check_ssl_expiration.sh
poczta.onet.pl:443 WILL EXPIRE ON Oct 14 06:10:33 2014 GMT
ALARM !!! DOMAIN some.kind.of.mons.tr:443 EXPIRE ON Jul 3 13:19:18 2013 GMT
File contains domains:
shamrock@alucard:~$ cat domeny.txt
poczta.onet.pl:443
some.kind.of.mons.tr:443