Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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