Created
February 2, 2018 19:01
-
-
Save jamesalbert/ed4273936836edad8ab83bb0291982dd to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
function usage { | |
echo "view-log <status-regex> [--pull]" | |
exit 1 | |
} | |
[[ "$1" == "" ]] && usage || filter=$1 | |
[[ ! -d ~/.awslogs ]] && mkdir ~/.awslogs | |
opscore iam refresh --account cloudbees-main --role infra-admin --profile log-admin | |
IFS=- read year month day <<< "$(date +%Y-%m-%d)" | |
s3path="s3://cb-ecs-elb-logs/AWSLogs/538462253088/elasticloadbalancing/us-east-1/$year/$month/$day" | |
latest=`aws s3 ls $s3path --recursive --profile log-admin | sort | tail -n1` | |
read date time size log_s3_path <<< $latest | |
log_zipped=`basename $log_s3_path` | |
log_ext="${log_zipped##*.}" | |
log_name="${log_zipped%.*}" | |
echo "date: $date" | |
echo "time: $time" | |
echo "size: $size bytes" | |
echo "log in s3: $log_s3_path" | |
echo "log zipped: $log_zipped" | |
echo "log ext: $log_ext" | |
echo "log name: $log_name" | |
aws s3 cp $s3path/$log_zipped ~/.awslogs/$log_zipped --profile log-admin | |
gzip -df ~/.awslogs/$log_zipped | |
cat ~/.awslogs/$log_name | cut -d' ' -f2,9,10,4,5,13,14 | grep -E "$filter \"" | |
opscore -q iam expire --profile log-admin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment