Created
October 25, 2018 16:16
-
-
Save vrdominguez/70544ae5c7cf9764e4f12d1112cb0bae to your computer and use it in GitHub Desktop.
Obtener fecha de caducidad de un certificado remoto
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 | |
############################################################################### | |
# Calcula los dias que quedan para que un certificado remoto caduque, de modo # | |
# que podamos controlar si ya deberia de estar renovado # | |
############################################################################### | |
if [ $# -eq 0 ]; then | |
echo "No se ha pasado un dominio" | |
exit 1 | |
fi | |
# Obtenemos la fecha de caducidad del certificado del dominio solicitado | |
CADUCIDAD=$( | |
echo | openssl s_client -servername $1 -connect $1:443 2>/dev/null | \ | |
openssl x509 -noout -enddate | \ | |
cut -d= -f2- | |
) | |
# Calculamos los dias que le quedan al certificado | |
echo "( `date -d \"$CADUCIDAD\" +%s` - `date +%s`) / (24*3600)" | bc -l | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment