Skip to content

Commit 88c08fb

Browse files
committed
better checking for OS type to use the correct date command
1 parent fa1471d commit 88c08fb

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

utils/log-collector

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,21 @@ done
7373

7474
# Currently only collects the last 24h of logs, but it might be good to be able to specify a different value for this.
7575

76-
logAge=$(date --date="1day" "+%s000")
77-
78-
# check if we're running on a macOS based system
76+
# check if we're running on a macOS based system, otherwise use the GNU-based date syntax
7977
if [[ $OSTYPE == 'darwin'* ]]; then
8078
logAge=$(date -v-1d "+%s000")
79+
else
80+
logAge=$(date --date="1day" "+%s000")
8181
fi
8282

83-
84-
8583
# Collect some information about the Lambda function and associated log groups
8684
lambdaFunction=$(aws cloudformation describe-stack-resources --stack-name "$stackName" --logical-resource-id Autoscaling --query "StackResources[*].PhysicalResourceId" --output text | sed -nr 's/.*stack\/(.*)\/.*/\1/p')
8785
lambdaLogGroup=$(aws cloudformation describe-stack-resources --stack-name "$lambdaFunction" --logical-resource-id LogGroup --query "StackResources[*].PhysicalResourceId" --output text)
8886
logStreams=$(aws logs describe-log-streams --log-group-name "$lambdaLogGroup" --order-by LastEventTime --query "logStreams[?creationTime > \`$logAge\`] | [*].logStreamName" --output text | tr -s '[:space:]' '\n')
8987

9088
# Iterate through all of the log streams we collected from the lambda log group
9189
echo "Collecting Lambda logs for $lambdaFunction"
90+
9291
for i in $logStreams
9392
do
9493
fileName=$(echo "$i" | sed -r 's/\//-/g')

0 commit comments

Comments
 (0)