Created
October 7, 2021 08:39
-
-
Save el-gringo/67514739d8e8b14cd6206724fa0af5bd to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env sh | |
root_path=$1 | |
usage() { | |
echo "Usage: check_certificates.sh PATH" | |
echo "" | |
echo "Search for any certificate (*.pem, *.crt) in PATH then sort them by validity" | |
} | |
if [ -z "$root_path" ]; then | |
usage | |
return 1 | |
fi | |
now=$(date +%s) | |
for certificate in $(find $root_path -name "*.crt" -o -name "*.pem"); do | |
certificate_filepath=$(readlink -f $certificate) | |
expiration_date=$(openssl x509 -noout -text -in $certificate_filepath | sed '/^ *Not After/ { s/^[^:]*://; p }; d') | |
expires=$(date -d "$expiration_date" +"%Y-%m-%d") | |
echo "$expires $certificate_filepath" | |
done | sort |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment