Get the size of a S3 Bucket's sub-folder through bash script
3
votes
2
answers
2725
views
I am trying to write a bash script to get the total size of sub folders in a S3 bucket.
My bucketpath **s3://path1/path2/subfolders**
Inside the path2 folder i have many sub-folder like
2019_06
2019_07
2019_08
2019_09
2019_10
2019_11
2019_12
I need to get the size of each subfolder in a bash script.
I wrote a script like
**
#!/bin/bash
FILES=$(mktemp)
aws s3 ls "s3://path1/path2/" >> "$FILES"
cat $FILES
echo
for file in $FILES
do
if [ ! -e "$file" ]
then
s3cmd du -r s3://path1/path2/$file
echo "$file"; echo
continue
fi
echo
done
**
The output of cat $tmpfile is as below
2019_06
2019_07
2019_08
2019_09
2019_10
2019_11
2019_12
But am getting error. While passing the variable into the for loop. Ideally my aim is like for each iteration when for loop runs inside do .....The command should be like
**s3cmd du -r s3://path1/path2/2019_06**
**s3cmd du -r s3://path1/path2/2019_07**
**s3cmd du -r s3://path1/path2/2019_08**
etc...
So that i can get the total size of the folder
Kindly help!
Asked by clarie
(95 rep)
Apr 29, 2020, 06:12 AM
Last activity: Dec 24, 2022, 06:24 AM
Last activity: Dec 24, 2022, 06:24 AM