Skip to content

Instantly share code, notes, and snippets.

@mkjsix
mkjsix / read-retention.sh
Last active October 18, 2019 07:26
Read retention policies for AWS CloudWatch Log Groups, for a profile and a region
#!/bin/bash
# Example - to read the logs retention policy for your default AWS account in region eu-west-1, execute the command:
# read-retention.sh default eu-west-1
export AWS_PROFILE=$1
export AWS_REGION=$2
echo "AWS_PROFILE=$AWS_PROFILE, AWS_REGION=$AWS_REGION"
while read -r i;
do (printf "%s: " "$i" && aws logs describe-log-groups --region "$AWS_REGION" --log-group-name-prefix "$i" --query 'logGroups[0].retentionInDays');
done < <(aws logs describe-log-groups --region "$AWS_REGION" --query 'logGroups[*].[logGroupName]' | grep / | sed 's/"//g')
@mkjsix
mkjsix / set-retention.sh
Last active June 6, 2024 14:07
Set retention policies for AWS CloudWatch Log Groups, for a profile and a region
#!/bin/bash
# Example - to set the logs retention policy for your default AWS account in region eu-west-1 to 5 days, execute the command:
# set-retention.sh default eu-west-1 5
export AWS_PROFILE=$1
export AWS_REGION=$2
RETENTION_DAYS=${3:-30}
echo "AWS_PROFILE=$AWS_PROFILE, AWS_REGION=$AWS_REGION, RETENTION_DAYS=$RETENTION_DAYS"
while read -r i;
do (aws logs put-retention-policy --region "$AWS_REGION" --log-group-name "$i" --retention-in-days "$RETENTION_DAYS" );
done < <(aws logs describe-log-groups --region "$AWS_REGION" --query 'logGroups[*].[logGroupName]' | grep / | sed 's/"//g')
@mkjsix
mkjsix / jar-version.sh
Last active October 16, 2019 11:46
Extract the POM version from JAR file
#!/bin/bash
VERSION=$(unzip -q -c "$1" META-INF/MANIFEST.MF | grep "Implementation-Version:" | awk '{print $2}' | sed 's/["\n\r]//g')
printf "%s" "$VERSION"
@mkjsix
mkjsix / export.sh
Created March 8, 2022 08:45
A bash script to export all MongoDB collections from a single database to JSON files
#!/bin/bash
if [ ! $1 ]; then
echo " Example of use: $0 database_name [dir_to_store]"
exit 1
fi
db=$1
out_dir=$2
if [ ! $out_dir ]; then
out_dir="./"