Created
July 19, 2024 23:40
-
-
Save rkok/25a9500d67c57667c4913c1a7ce22e69 to your computer and use it in GitHub Desktop.
Bash function to check whether/when a WordPress URL was cached by WP Rocket
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
# Usage: wprockettest https://example.com/some-path/ | |
wprockettest() { | |
URL="$1" | |
echo -n "$URL --> " | |
RES="$(curl -ksvG "$URL" 2>&1)" | |
CODE="$(echo "$RES" | grep -E '^< HTTP' | awk '{print $3}')" | |
CACHE_STATUS="Not cached" | |
if [ "$CODE" == "200" ]; then | |
CACHEDATE="$(echo "$RES" | grep -oE 'cached@[0-9]+' | cut -d@ -f2)" | |
if [ -n "$CACHEDATE" ]; then | |
CACHE_STATUS="Cached at $(date -d @"$CACHEDATE")" | |
NCACHED=$((NCACHED+1)) | |
fi | |
fi | |
echo "$CODE - $CACHE_STATUS" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment