Skip to content

Instantly share code, notes, and snippets.

@kritchie
Last active August 12, 2019 20:35
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 kritchie/58b9f14f06455942f61ee371556f46ba to your computer and use it in GitHub Desktop.
Save kritchie/58b9f14f06455942f61ee371556f46ba to your computer and use it in GitHub Desktop.
Bash snippets
#
# Get TLS certificates expiration
# Useful to verify when TLS certificates will expire
readonly BLUE='\033[0;34m'
readonly RED='\033[0;31m'
readonly NC='\033[0m' # No Color
validate(){
if [[ -z "$1" || -z "$2" ]]; then
echo "Validate needs 2 arguments: validate [host] [port]"
return
fi
HOST=$1
PORT=$2
VAL=$(echo | openssl s_client -connect ${HOST}:${PORT} 2>/dev/null | openssl x509 -noout -dates | grep notAfter)
AFTER=$(echo -e "${VAL} ${HOST}" | awk '{split($0,a,"="); split(a[2],b,"GMT"); print b[1]}')
URL=$(echo -e "${VAL} ${HOST}" | awk '{split($0,a,"="); split(a[2],b,"GMT"); print b[2]}')
echo -e "${RED} ${AFTER} ${BLUE} ${URL} ${NC}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment