Created
March 25, 2022 13:54
-
-
Save dacgray/35a384d10fdd270ed530abb963893508 to your computer and use it in GitHub Desktop.
Fetch AWS Cloudwatch exported S3 logs, extract, combine and sort.
This file contains 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 | |
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