-
-
Save chilledornaments/1b03cfc3a9f41d86aa9fd38de6c4703e to your computer and use it in GitHub Desktop.
Bash SSL Certificate Expiration Check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
TARGETS=( | |
'example.com' | |
'example.net' | |
'example.org' | |
) | |
SLACK_URL='Your incoming webhook'. # 'https://hooks.slack.com/services/SOMETHING/SOMETHING ELSE' | |
emoji=":terminator:" | |
uname="CERT CHECKER" | |
channel="#alerts" | |
DAYS=7; | |
for TARGET in ${TARGETS[*]}; | |
expirationdate=$(date -d "$(: | openssl s_client -connect $TARGET:443 -servername $TARGET 2>/dev/null \ | |
| openssl x509 -text \ | |
| grep 'Not After' \ | |
| awk '{print $4,$5,$7}')" '+%s'); | |
in7days=$(($(date +%s) + (86400*$DAYS))); | |
if [ $in7days -gt $expirationdate ]; then | |
message="Certificate for $TARGET expires in less than $DAYS days" | |
payload="payload={\"channel\": \"$channel\", \"username\": \"$uname\", \"icon_emoji\": \"$emoji\", \"text\": \"${message}\"}" | |
curl -m 5 --data-urlencode "${payload}" $SLACK_URL | |
exit 0 | |
else | |
exit 5 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
now for Slack!