AWS 记录 tail --follow 直到找到短语

问题描述 投票:0回答:1

我想准备一个 Github Action 工作流程,它将使用 aws log CLI 从我部署的应用程序打印实时日志,但也会在找到定义的短语后停止跟踪/打印日志。我尝试使用 awk 但没有结果。有什么建议如何实现这一目标吗?

我尝试使用 awk 但没有结果。脚本不会停止打印日志

github-actions aws-cli amazon-cloudwatchlogs
1个回答
0
投票

受到https://unix.stackexchange.com/a/61833的启发,看起来这种情况下的问题在于管道缓冲。有关详细信息,请阅读链接问题的不同答案 - 看起来这里可能涉及不同的缓冲类型。

特定于跟踪 CloudWatch Logs,对于 Mac/FreeBSD,可能的解决方案可能如下所示:

script -q /dev/null aws logs tail /aws/ssm/my-run-document --follow \
  | sed '/Stop on this line/ q'

...在 Linux 系统上它将是:

script -q -c 'aws logs tail /aws/ssm/my-run-document --follow' /dev/null \
  | sed '/Stop on this line/ q'
© www.soinside.com 2019 - 2024. All rights reserved.