Skip to content

Instantly share code, notes, and snippets.

@smeghead
Created November 10, 2011 01:01
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 smeghead/1353751 to your computer and use it in GitHub Desktop.
Save smeghead/1353751 to your computer and use it in GitHub Desktop.
check ssl cert expire.
#!/bin/sh
if [ $# == 0 ]; then
echo "usage: $1 <ssl cert file>"
exit 1
fi
FILENAME=$1
if [ ! -f "$FILENAME" ]; then
echo "ERROR: <ssl cert file> not exists. $FILENAME"
exit 1
fi
EXPIRE_EXP="$(openssl x509 -noout -text -in $FILENAME | grep 'Not After' | sed -e 's/[^:]\+: //')"
EXPIRE=$(date --date "$EXPIRE_EXP")
THRESHOLD=$(date -d "$EXPIRE_EXP -30 days" +"%s")
TODAY=$(date +"%s")
if [ $THRESHOLD -lt $TODAY ]; then
echo "SSL CERT FILE (WILL) EXPIRE!!!!! EXPIRE: $EXPIRE"
echo "$FILENAME"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment