Last active
December 17, 2015 03:29
-
-
Save mrpatrick/5543670 to your computer and use it in GitHub Desktop.
Print how many days left until an SSL certificate file expires. Usage: ssl_expire_days.py CERTFILE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import datetime | |
import subprocess | |
import sys | |
cert = sys.argv[1] | |
date_format = "%m/%d/%Y" | |
p = subprocess.Popen("openssl x509 -noout -in " + cert + " -enddate | sed 's/^[a-zA-Z]*=//g' | xargs --null date +" + date_format\ | |
+ " -d",stdout=subprocess.PIPE, shell=True) | |
(output, err) = p.communicate() | |
if output: | |
output = output.rstrip("\n") | |
d0 = datetime.datetime.today() | |
d1 = datetime.datetime(*(time.strptime(output, date_format)[0:3])) | |
delta = d1 - d0 | |
print(delta.days) | |
else: | |
print("Usage: python ssl_expires_days.py certfile"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now works with both python 2.4 and 2.7