Skip to content

Instantly share code, notes, and snippets.

@mephraums
Last active February 10, 2020 21:38
Show Gist options
  • Save mephraums/fe0def428d4dc6d425b48f808130970b to your computer and use it in GitHub Desktop.
Save mephraums/fe0def428d4dc6d425b48f808130970b to your computer and use it in GitHub Desktop.
Check list of domains and output text file with certificate expiry dates
#!/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