Created
January 28, 2013 12:08
-
-
Save theothertom/4655006 to your computer and use it in GitHub Desktop.
Time in days remaining for SSL certs, for use by monitoring systems.
This file contains 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 | |
host=$1 | |
port=$2 | |
#This is a little bit nasty with all the piping and all | |
cert_expire=`echo | openssl s_client -showcerts -connect $host:$port 2>/dev/null |sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | openssl x509 -noout -subject -dates | grep notAfter | awk -F= '{print $2}'` | |
cert_expire_unix=`date --date="$cert_expire" +%s` | |
current_time_unix=`date +%s` | |
timediff_days=$((($cert_expire_unix - $current_time_unix) / 86400)) | |
#For monitoring systems | |
echo $timediff_days | |
#More output when running manually | |
if [[ -t "0" || -p /dev/stdin ]] | |
then | |
echo "Cert for $host expires on $cert_expire" >&2 | |
echo "Current (local) time is `date`" >&2 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment