Last active
May 5, 2022 13:02
-
-
Save christianascone/d29f11e9080426b8179957f9ee1efe45 to your computer and use it in GitHub Desktop.
Delete files older than 15 days stored on S3 bucket
This file contains hidden or 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
| BUCKETNAME=$1 | |
| PROFILE=$2 | |
| URL=$3 | |
| aws s3 ls $BUCKETNAME/ --profile $PROFILE --endpoint-url=$URL | while read -r line; | |
| do | |
| createDate=`echo $line|awk {'print $1" "$2'}` | |
| createDate=`date -d"$createDate" +%s` | |
| olderThan=`date --date "15 days ago" +%s` | |
| if [[ $createDate -lt $olderThan ]] | |
| then | |
| fileName=`echo $line|awk {'print $4'}` | |
| if [[ $fileName != "" ]] | |
| then | |
| echo "Deleting $fileName" | |
| aws s3 rm s3://$BUCKETNAME/$fileName --profile $PROFILE --endpoint-url=$URL | |
| fi | |
| fi | |
| done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment