Shell script to find out aliases and their expiration in cacerts
#!/bin/bash
# Set the path to the Java installation directory
JAVA_HOME="/opt/java"
# Set the password for the keystore
KEYSTORE_PASS="keystore_password"
# List all aliases in the keystore
ALIASES=$(keytool -list -v -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass $KEYSTORE_PASS | grep "Alias name:" | awk '{print $3}')
# Loop through the aliases and get the expiration date for each certificate
for ALIAS in $ALIASES; do
# Get the expiration date in human-readable format
EXP_DATE=$(keytool -list -v -alias $ALIAS -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass $KEYSTORE_PASS | grep "Valid from" | awk '{print $3 " " $4 " " $7 " " $6}')
# Print the alias name and expiration date
echo "Alias Name: $ALIAS"
echo "Expiration Date: $EXP_DATE"
echo ""
done
Replace "/path/to/java" with the path to your Java installation directory, and "keystore_password" with the password for the cacerts keystore.
The script uses the keytool command to list all the aliases in the keystore, then loops through each alias and gets the expiration date for the corresponding certificate. The alias name and expiration date are printed for each certificate.
To run the script, save it as a file with a .sh extension (e.g. check-all-certs-expiration.sh), make it executable with the command "chmod +x check-all-certs-expiration.sh", then run it with the command "./check-all-certs-expiration.sh". Note that you may need to run the script with elevated privileges (e.g. sudo) to access the cacerts keystore.
Comments
Post a Comment