Skip to content

Instantly share code, notes, and snippets.

@eksiscloud
Created June 23, 2025 13:49
Show Gist options
  • Save eksiscloud/0ca57f2e59ccd4792d0a0ec044d35929 to your computer and use it in GitHub Desktop.
Save eksiscloud/0ca57f2e59ccd4792d0a0ec044d35929 to your computer and use it in GitHub Desktop.
Makes manually purge in Varnish using xkeys, can used with several hosts
#!/bin/bash
# chmod +x purge.sh
# DEFAULT
DEFAULT_DOMAIN="1.example.tld"
# MANUAL
function usage() {
echo "Use:"
echo " $0 <target> <url|xkeytag[,xkeytag2,...]>"
echo
echo "Examples:"
echo " $0 poochie https://1.example.tld/2025/05/article/"
echo " $0 poochie frontpage"
echo " $0 poochie sidebar,frontpage,article-123"
echo
echo "Targets:"
echo " poochie -> 1.example.tld"
echo " kitty -> 2.example.tld"
exit 1
}
# DOMAINS
case "$1" in
poochie) DOMAIN="1.example.tld" ;;
kitty) DOMAIN="2.example.tld" ;;
"") usage ;;
*) echo "Unknown target: $1"; usage ;;
esac
# REMOVE FIRST PARAMETER
shift
# CHECK IF VALUE IS GIVEN
if [ -z "$1" ]; then
usage
fi
# CHECK IF IT IS URL OR XKEY
if [[ "$1" =~ ^https?:// ]]; then
echo "Sending PURGE URL: $1"
curl -s -X PURGE "$1" --http1.1
else
echo "Sending Xkey PURGE to target: $DOMAIN"
curl -s -X PURGE "https://${DOMAIN}/" \
-H "Host: ${DOMAIN}" \
-H "xkey-purge: $1" \
--http1.1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment