Skip to content

Instantly share code, notes, and snippets.

@chilledornaments
Forked from cgmartin/check-certs.sh
Last active January 20, 2020 08:48
Show Gist options
  • Save chilledornaments/1b03cfc3a9f41d86aa9fd38de6c4703e to your computer and use it in GitHub Desktop.
Save chilledornaments/1b03cfc3a9f41d86aa9fd38de6c4703e to your computer and use it in GitHub Desktop.
Bash SSL Certificate Expiration Check
#!/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
@chilledornaments
Copy link
Author

now for Slack!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment