Created
May 7, 2020 11:37
-
-
Save kshailen/d16432cc33e964cdb20c6c9849acf58b to your computer and use it in GitHub Desktop.
Get Size details of all S3 buckets
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
#!/bin/bash | |
# exit when the command fails | |
set -o errexit; | |
# exit when try to use undeclared var | |
set -o nounset; | |
Total_num_of_buckets=`aws s3 ls s3:// | awk '{print $NF}'| wc -l` | |
printf "%s: %4d\n" "Total Number of s3 buckets" ${Total_num_of_buckets} | |
printf "%s: %4s\n" "Bucket Name" "Bucket Size" | |
for bucket in `aws s3 ls s3:// | awk '{print $NF}'`; do printf "$bucket :"; aws s3 ls s3://$bucket --recursive --human-readable --summarize | tail -1 | tr -d 'Total Size:'; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment