Skip to content

Instantly share code, notes, and snippets.

@el-gringo
Created October 7, 2021 08:39
Show Gist options
  • Save el-gringo/67514739d8e8b14cd6206724fa0af5bd to your computer and use it in GitHub Desktop.
Save el-gringo/67514739d8e8b14cd6206724fa0af5bd to your computer and use it in GitHub Desktop.
#!/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