Last active
February 10, 2020 21:38
-
-
Save mephraums/fe0def428d4dc6d425b48f808130970b to your computer and use it in GitHub Desktop.
Check list of domains and output text file with certificate expiry dates
This file contains 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
#!/bin/bash | |
input="domains.txt" #text file with each domain on a new line | |
output="expiry.txt" #where the result should be written to | |
echo -n "" > $output | |
while read line; do | |
domain=$line | |
dates=$(echo | openssl s_client -servername $domain -connect $domain:443 2>/dev/null | openssl x509 -noout -dates) | |
not_after=$(echo $dates|cut -d '=' -f 3 | tr -dc '[:alnum:]:[:space:]') | |
#echo $not_after | |
IFS=', ' read -r -a array <<< "$not_after" | |
expiry=$(date -jf "%Y %b %d %T %Z" "${array[3]} ${array[0]} ${array[1]} ${array[2]} ${array[4]}" +"%Y-%b-%d") #Feb 23 12:00:00 2020 GMT | |
#echo $expiry | |
echo "$expiry | $domain" >> $output | |
done < $input | |
sort -o $output -n -t"-" -k1n -k2M -k3n $output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment