Skip to content

Instantly share code, notes, and snippets.

@marutiprasad
Last active February 7, 2021 08:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marutiprasad/764ac69815ee43714201068388269897 to your computer and use it in GitHub Desktop.
Save marutiprasad/764ac69815ee43714201068388269897 to your computer and use it in GitHub Desktop.
Akamai purge in the event of dispatcher / local cache purge
#!/bin/sh
# Before running this script, plese ensure the following tools are installed.
# 1. inotifywait (yum install inotify-tools)
# 2. akamai-purge (script https://github.com/akamai/cli-purge)
# 3. Keep the CCU API credentials in the .edgerc file in the user home dir.
ROOTDIR='/data/www/htdocs/publish/content/site1'
HOST_URL='https://www.myhost.com'
inotifywait -m -r -e delete $ROOTDIR |
while read dir ev file; do
if [ "$ev" = "DELETE" ]; then
FILEPATH=${dir}${file}
URI=${FILEPATH#$ROOTDIR}
echo "$(date) - This file is deleted:$URI" >> purge.log
WEB_URL=$HOST_URL$URI
# you can add "--staging" in case of staging request.
# change the akamai-purge path as per your installation.
./akamai-purge "invalidate" "$WEB_URL" >> purge.log
echo "$(date) - purge request has been raised for:$WEB_URL" >> purge.log
else
echo "Observed event: $ev on file: $file"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment