Skip to content

Instantly share code, notes, and snippets.

@PatrickRoumanoff
Last active June 20, 2018 23:32
Show Gist options
  • Save PatrickRoumanoff/f717d921fe97bed4412541a47da67e93 to your computer and use it in GitHub Desktop.
Save PatrickRoumanoff/f717d921fe97bed4412541a47da67e93 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, with a minimal set of dependencies: curl & sed. Replace username, password and objectIds
#!/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"
@smicha
Copy link

smicha commented Jun 20, 2018

Did you get this to work . --user username:password refers to the client token : access token ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment