Skip to content

Instantly share code, notes, and snippets.

@magickatt
Created January 4, 2021 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magickatt/6059cc28214215514c915f5357e4aa8b to your computer and use it in GitHub Desktop.
Save magickatt/6059cc28214215514c915f5357e4aa8b to your computer and use it in GitHub Desktop.
Check at specified intervals whether an SSL certificate is valid
#!/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