Created
January 4, 2021 20:05
-
-
Save magickatt/6059cc28214215514c915f5357e4aa8b to your computer and use it in GitHub Desktop.
Check at specified intervals whether an SSL certificate is valid
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 | |
URI=https://www.yahoo.com | |
INTERVAL_IN_SECONDS=0.5 | |
RESULTS_PER_LINE=50 | |
echo "Checking $URI at ${INTERVAL_IN_SECONDS}s intervals..." | |
check_uri () { | |
if [ $COUNTER -le 0 ]; then | |
TIME=$(date +"%T") | |
printf "\n[${TIME}] " | |
COUNTER=$RESULTS_PER_LINE | |
fi | |
# https://serverfault.com/a/749381 | |
CHECK_URI_RESULT=$(curl --insecure -vvI $URI 2>&1 | awk 'BEGIN { cert=0 } /^\* Server certificate:/ { cert=1 } /^\*/ { if (cert) print }') | |
echo $CHECK_URI_RESULT | grep --quiet "SSL certificate verify ok" | |
if [ $? -eq 0 ]; then | |
printf ✓ | |
else | |
printf ✗ | |
fi | |
let "COUNTER-=1" | |
} | |
COUNTER=0 | |
while true; do | |
check_uri | |
sleep $INTERVAL_IN_SECONDS | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment