Last active
June 20, 2018 23:32
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
Did you get this to work . --user username:password refers to the client token : access token ?