Skip to content

Instantly share code, notes, and snippets.

@oservieres
Last active November 11, 2020 10:14
Show Gist options
  • Save oservieres/8914194 to your computer and use it in GitHub Desktop.
Save oservieres/8914194 to your computer and use it in GitHub Desktop.
Check ssl certificates expiration dates from apache conf files
#!/bin/bash
FILES=${1}
THRESHOLD_DATE=`date --date "+30 day" +%Y%m%d`
DOMAINS=`grep "ServerName\|ServerAlias" ${FILES} | cut -d":" -f2 | sed "s/\s*ServerName//g" | sed "s/\s*ServerAlias//g" | sort | uniq`
for DOMAIN in ${DOMAINS}
do
FILE=`grep ${DOMAIN} ${FILES} | cut -d":" -f1 | sort | uniq`
if [ "" == "$FILE" ]
then
continue
fi
nslookup ${DOMAIN} &> /dev/null || continue
echo -n "\"${DOMAIN}\";"
DATE=`echo | openssl s_client -connect ${DOMAIN}:443 2>/dev/null | openssl x509 -noout -dates | grep notAfter | sed "s/notAfter=//g"`
echo -n "\"${DATE}\";"
FORMATTED_DATE=`date -d "${DATE}" +%Y%m%d`
if [ "${THRESHOLD_DATE}" -gt "${FORMATTED_DATE}" ]
then
echo -n "\"WARNING\""
else
echo -n "\"OK\""
fi
echo ""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment