Created
June 15, 2021 08:21
-
-
Save rhamaa/aad602ad3f2117d1172dd658df619e1e to your computer and use it in GitHub Desktop.
Retention delete bash script S3
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
# Source : https://stackoverflow.com/questions/50467698/how-to-delete-files-older-than-7-days-in-s3 | |
aws s3 ls BUCKETNAME/ | while read -r line; | |
do | |
createDate=`echo $line|awk {'print $1" "$2'}` | |
createDate=`date -d"$createDate" +%s` | |
olderThan=`date --date "7 days ago" +%s` | |
if [[ $createDate -lt $olderThan ]] | |
then | |
fileName=`echo $line|awk {'print $4'}` | |
if [[ $fileName != "" ]] | |
then | |
aws s3 rm BUCKETNAME/$fileName | |
fi | |
fi | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment