Skip to content

Instantly share code, notes, and snippets.

@j13k
Created November 21, 2022 08:08
Show Gist options
  • Save j13k/26e388e64c77b12ed084fb7ff4e75766 to your computer and use it in GitHub Desktop.
Save j13k/26e388e64c77b12ed084fb7ff4e75766 to your computer and use it in GitHub Desktop.
Primes a WordPress website cache by crawling each resource linked in sitemap.xml.
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
if [[ "${TRACE-0}" == "1" ]]; then
set -o xtrace
fi
usage() {
echo '
Usage: ./prime_wordpress_website_cache.sh HOSTNAME
Primes a WordPress website cache by crawling each resource linked in sitemap.xml.
'
}
if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then
usage
exit
fi
if [ -z "${1-}" ]; then
echo '
HOSTNAME not specified
'
usage
exit 1
fi
#cd "$(dirname "$0")"
main() {
wget --quiet "https://${1}/sitemap.xml" --output-document - |
grep -Eo "https?://${1}/[^<]+" |
wget --quiet -i - --output-document - |
grep -Eo "https?://${1}/[^<]+" |
wget -i - --output-document /dev/null
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment