-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArtifactory-Cleanup.sh
More file actions
executable file
·21 lines (16 loc) · 1.59 KB
/
Artifactory-Cleanup.sh
File metadata and controls
executable file
·21 lines (16 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
# find all artifacts created in 2013, time are expressed in milliseconds
# grep look for uri attribute in JSON results returned then awk take the corresponding value of the uri attribute. The first 2 sed commands remove the last character and the last sed command remove the first character, ie stripping off the comma and double quotes from the URL in awk
USER=$1
PASSWORD=$2
RESULTS=`curl -k -X GET -u $USER:$PASSWORD "http://artifactory.dek.corp.mvideo.ru/artifactory/api/search/creation?from=00&to=1491004800000&repos=ext-release-local" | grep uri | awk '{print $3}' | sed s'/.$//' | sed s'/.$//' | sed -r 's/^.{1}//' | grep ui-asset`
#RESULTS=`curl -k -X GET -u $USER:$PASSWORD "http://artifactory.dek.corp.mvideo.ru/artifactory/api/search/usage?notUsedSince=1491004800000&repos=ext-release-local" | grep uri | awk '{print $3}' | sed s'/.$//' | sed s'/.$//' | sed -r 's/^.{1}//'`
for RESULT in $RESULTS ; do
echo "fetching path from $RESULT"
# from the URL we fetch the download uri to remove
# grep look for downloadUri attribute in JSON results returned then awk take the corresponding value of the downloadUri attribute. The first 2 sed commands remove the last character and the last sed command remove the first character, ie stripping off the comma and double quotes from the URL in awk
PATH_TO_FILE=`curl -s -X GET -u $USER:$PASSWORD $RESULT | grep downloadUri | awk '{print $3}' | sed s'/.$//' | sed s'/.$//' | sed -r 's/^.{1}//'`
echo "deleting path $PATH_TO_FILE"
# deleting the corresponding artifact at last
curl -X DELETE -u $USER:$PASSWORD $PATH_TO_FILE
done