Skip to content

Instantly share code, notes, and snippets.

@vortizhe
Created May 23, 2013 11:21
Show Gist options
  • Save vortizhe/5635377 to your computer and use it in GitHub Desktop.
Save vortizhe/5635377 to your computer and use it in GitHub Desktop.
Script to purge varnish specific url
#!/bin/bash
cmd="sudo varnishadm -T localhost:6082 -S /etc/varnish/secret"
page=$(echo $1 | awk -F'/' -v OFS='/' '{sub(/https?:\/\//, ""); $1=""; print $0}')
if [ -z "$1" ]; then
echo "ERROR: please provide a URL to ban.."
exit 1
fi
if [ -z "$page" ]; then
page="/"
fi
echo "purging old version from cache.."
$cmd "ban req.url ~ ^$page\$" | sed '/^$/d'
echo "populating cache with new page content.."
curl -sL -w "%{http_code} %{url_effective}\n" http://tudomain${page} -o /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment