Skip to content

Instantly share code, notes, and snippets.

@juanxhos
Forked from PatrickRoumanoff/purgeAkamai.sh
Last active January 20, 2019 20:04
Show Gist options
  • Save juanxhos/031f821c523139801a76b6fe0ae2589f to your computer and use it in GitHub Desktop.
Save juanxhos/031f821c523139801a76b6fe0ae2589f to your computer and use it in GitHub Desktop.
A bash script for a ci build that is purging the Akamai cache and wait for the task to complete
#!/bin/bash
#strict mode
set -euo pipefail
IFS=$'\n\t'
URL="https://api.ccu.akamai.com/ccu/v2"
CURL="curl --fail --silent --header \"Content-Type:application/json\" --user username:password"
echo '{"type":"cpcode","objects":["000000","111111"]}' > data.json
echo `date "+%Y-%m-%dT%H:%M:%S"` "Purge started"
JSON=$(eval ${CURL} ${URL}/queues/default --data @data.json)
rm data.json
purgeId=`echo $JSON | sed 's/.*"purgeId": "\([^"]*\)".*/\1/'`
STATUS="Pending"
while [ "$STATUS" != "Done" ]
do
pingAfterSeconds=`echo $JSON | sed 's/.*"pingAfterSeconds": \([0-9]*\).*/\1/'`
echo `date "+%Y-%m-%dT%H:%M:%S"` "${STATUS}, sleeping ${pingAfterSeconds}s"
sleep ${pingAfterSeconds}s
JSON=$(eval curl ${CURL} ${URL}/purges/${purgeId})
STATUS=`echo $JSON | sed 's/.*, "purgeStatus": "\([^"]*\)", .*/\1/'`
done
echo `date "+%Y-%m-%dT%H:%M:%S"` "Purge finished"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment