Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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