externalscripts/certificate_expiration-bsd: Certificate expiration check (BSD date(1) variant) as external check (via TCP)
#!/bin/sh
echo | openssl s_client -connect $1:$2 2>/dev/null | \
sed -n '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p' | \
openssl x509 -enddate | grep notAfter| awk -F= '{print $2}' | \
while read l; do
t=`date -j -f "%b %d %T %Y %Z" "$l" +%s`
n=`date +%s`
echo `expr $t - $n`
done