github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/scripts/s3/list-bucket-inventory.sh (about)

     1  #!/bin/bash
     2  
     3  while getopts n:p:b:f: flag
     4  do
     5  	case "$flag" in
     6  		b) BUCKET=${OPTARG};;
     7  	esac
     8  done
     9  
    10  print_usage() {
    11  	echo "Usage:"
    12  	echo "./list-bucket-inventory -b BUCKET_NAME"
    13  	echo
    14  	echo "The script displays all enabled inventory collectors for a bucket"
    15  	echo
    16  	echo "  BUCKET_NAME - AWS bucket name for which inventory will be enabled"
    17  }
    18  
    19  RED='\033[0;31m'
    20  NC='\033[0m'
    21  
    22  if [[ -z "${BUCKET}" ]]; then
    23  	printf "${RED}Error${NC}: bucket name is not defined.\n"
    24  	print_usage
    25  	exit 1
    26  fi
    27  
    28  CFG=`aws s3api list-bucket-inventory-configurations --bucket ${BUCKET}`
    29  
    30  printf "ID\tPREFIX\tFREQUENCY\n"
    31  OUT=`echo $CFG | jq '"\(.InventoryConfigurationList[] .Id) \(.InventoryConfigurationList[] .Destination .S3BucketDestination .Prefix) \(.InventoryConfigurationList[] .Schedule .Frequency)"'`
    32  OUT=`echo $OUT | tr -d '"'`
    33  OUT=`echo $OUT | tr ' ' "\t"`
    34  printf "$OUT\n"