check ssl certificate expiry dates

Another one for today.. :-D
I wanted to find a quick way to show me the expiry dates of ssl certificates on the fly, without going through any browsers etc.
A combination of sed and openssl did the job.

``` {.lang:sh .decode:true} echo "" | openssl s_client -showcerts -connect www.ubs.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'| openssl x509 -noout -subject -dates

and the output of it looks like this:

``` {.lang:default .highlight:0 .decode:true}
depth=3 /C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification Authority
verify error:num=19:self signed certificate in certificate chain
verify return:0
DONE
subject= /1.3.6.1.4.1.311.60.2.1.3=CH/businessCategory=V1.0, Clause 5.(b)/serialNumber=48-720-1915/C=CH/postalCode=CH-8098/ST=Zuerich/L=Zuerich/street=Bahnhofstrasse 45/O=UBS AG/OU=FCEXTIIZurich1232009/CN=www.ubs.com
notBefore=Mar 12 00:00:00 2009 GMT
notAfter=May 29 23:59:59 2011 GMT

Of course you can do this for any port, not just 443 (https usually). So IMAPS (993) works just as fine.

Thanks for reading!
Raphi