Bash profile function to purge URLs in Varnish

UPDATE 2011-11-18: Here's updated code, that immediately refreshes the cache with curl after purging.

Here's a quick little function I put in my .bashrc to purge URLs and display the last three URLs purged:

# varnish purge
vpurge() {
        local url=$1
        local c="sudo varnishadm -T -S /etc/varnish/secret"
        if [ "$url" != "" ]; then
          $c purge.url $url && $c purge.list | head -3
          echo Error: please provide a URL to purge..

On failure:

$ vpurge
Error: please provide a URL to purge..

On success:

$ vpurge /alain/bash-profile-function-to-purge-urls-in-varnish
0x7f31821f3580 1291983660.622135     0 	req.url ~ /alain/bash-profile-function-to-purge-urls-in-varnish
0x7f31821f34c0 1291983640.244712     1 	req.url ==
0x7f31821f3460 1291983640.243777     0 	req.url ==

1 Comment

  • 1. Alain Kelder is a Giant D&hellip replies at 18th July 2012, 11:45 am :

    […] changing pages in varnish cache, comes the updated version of single page refresh script. The previous version didn’t automatically refresh the cache with curl after […]

Leave a comment

NOTE: Enclose quotes in <blockquote></blockquote>. Enclose code in <pre lang="LANG"></pre> (where LANG is one of these).