Skip to content

Instantly share code, notes, and snippets.

@dacgray
Created March 25, 2022 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dacgray/35a384d10fdd270ed530abb963893508 to your computer and use it in GitHub Desktop.
Save dacgray/35a384d10fdd270ed530abb963893508 to your computer and use it in GitHub Desktop.
Fetch AWS Cloudwatch exported S3 logs, extract, combine and sort.
#!/bin/bash
set -eE
mkdir -p .log
rm -rf .log/*
aws s3 --profile PROFILE --region REGION sync s3://my-log-bucket/exportedlogs .log/
cd .log
mkdir -p ./extracted
mkdir -p ./combined
LIST=$(find . -type f -name '*.gz')
C=1
for FILE in $LIST; do
echo $FILE
gzip -dc < $FILE > ./extracted/$C.log
C=$(($C+1))
done;
find . -type f -name '*.log' -exec cat {} + >> ./combined/combined.log
# This step can take an incredibly long time. Comment out for large log sets.
sort ./combined/combined.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment