Skip to content

Instantly share code, notes, and snippets.

@luhaoming
Last active March 7, 2018 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luhaoming/7af02175a5538a4d9f564f9c8ba0d50f to your computer and use it in GitHub Desktop.
Save luhaoming/7af02175a5538a4d9f564f9c8ba0d50f to your computer and use it in GitHub Desktop.
check ssl cert expiration
#!/bin/bash
DAYS=30
RECIPIENT="username@email.com"
while read TARGET
do
if [ -z "$TARGET" ];then continue; fi
sslexpiredate=$(date +%s -d "$(:|openssl s_client -connect $TARGET:443 2>/dev/null | \
openssl x509 -noout -enddate|\
awk -F'=' '{print $2}')");
notafterdate=$(($(date +%s) + (86400*$DAYS)));
if [ $notafterdate -gt $sslexpiredate ]; then
echo "ssl of $TARGET will expire less than $DAYS" | \
mailx -s "SSL expiring notice" $RECIPIENT;
else
echo "OK - $TARGET"
fi;
done <$1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment