Skip to content

Instantly share code, notes, and snippets.

@jayers99
Last active March 9, 2019 01:09
Show Gist options
  • Save jayers99/309079a5535247747c07d2337daf7ea4 to your computer and use it in GitHub Desktop.
Save jayers99/309079a5535247747c07d2337daf7ea4 to your computer and use it in GitHub Desktop.
tail logs from s3 bucket
#!/bin/bash
export AWS_PROFILE=dev
FULLPATH="s3://somebucket/logs/AWSLogs/1234567890/elasticloadbalancing/us-west-2/2019/03/"
BUCKET=$(echo "$FULLPATH" | cut -d "/" -f3)
echo "#$BUCKET#";
echo ;
LASTFILES=$(aws s3 ls $FULLPATH --recursive | sort | tail -n 10 | awk '{print $4}')
rm ./lastfile
for i in $LASTFILES; do
if [ ! -f ./lastfile$i ]; then
aws s3 cp s3://$BUCKET/$i ./lastfile$i
fi
gunzip -c ./lastfile$i >> ./lastfile
done
cat ./lastfile | awk '{ cmd="date +%Y-%m-%dT%H:%M:%S -d"$2; cmd | getline myTime; close(cmd); print myTime, $4, $5, $9 }'
#cat ./lastfile | sed 's/h2/\n-----------------------------------------/g' | tr " " "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment