You have a list of domains and want to know which certificate runs out first. A short shell script and openssl will tell you, sorted by days left.
The script
Put one host per line in hosts.txt. Add a port for anything that isn't on 443, like mail.example.com:993.
#!/bin/sh
# usage: ./certdays.sh hosts.txt
while read -r line; do
[ -z "$line" ] && continue
host=${line%:*}; port=${line##*:}
[ "$port" = "$line" ] && port=443
end=$(echo | timeout 10 openssl s_client -connect "$host:$port" -servername "$host" 2>/dev/null \
| openssl x509 -noout -enddate 2>/dev/null | cut -d= -f2)
if [ -z "$end" ]; then echo "ERROR $line"; continue; fi
echo "$(( ($(date -d "$end" +%s) - $(date +%s)) / 86400 )) $line"
done < "$1" | sort -n
Output, with the most urgent first:
ERROR old.example.com
4 mail.example.com:993
27 shop.example.com
61 example.com
A negative number means it has already expired. ERROR means no TLS answer: the host is down, the name doesn't resolve,
or the port is wrong.
On macOS
macOS has BSD date and no timeout. Replace the date part with:
$(date -j -f "%b %e %T %Y %Z" "$end" +%s)
and drop timeout 10, or install coreutils and use gtimeout.
Mail servers on STARTTLS ports
Ports 25, 587 and 143 start in plain text, so the script gets no certificate there. Add -starttls smtp
(or imap) to the openssl line for those hosts, or keep them in a separate list.
See checking a mail server's certificate.
Run it every week
# crontab -e: Monday 08:00, mail only if something has under 21 days
0 8 * * 1 /usr/local/bin/certdays.sh /etc/certdays/hosts.txt | awk '$1 == "ERROR" || $1 < 21'
cron emails any output to you, so this only sends mail when there's a problem. That needs a working mail setup on the machine, and it stays silent if cron or the machine stops. Check that it still runs now and then.
Without a script
For a one-off look, the bulk checker checks up to 10 hosts at once in the browser, no account needed.