smi*_*lli 0 streaming grep shell-script stdout
我有两个命令,build
和deploy
. 目前我build
手动运行,用我自己的眼睛解析它的输出,并使用我在输出中找到的值作为deploy
. 该过程类似于:
$ build
==> amazon-ebs: amazon-ebs output will be in this color.
... hundreds of lines of output ...
==> Builds finished. The artifacts of successful builds are:
--> amazon-ebs: AMIs were created:
us-east-1: ami-19601070
$ deploy ami-19601070
... some more output ...
Run Code Online (Sandbox Code Playgroud)
(build
实际上是Packer,为了精明)
我想将这两个步骤结合在一个脚本中。粗略的大纲将包括以下内容:
build
0
并且输出包含字符串“AMIs was created”,否则中止ami-19601070
从输出中提取 AMI 编号 ( )deploy ami-19601070
我试图想出将所有内容连接在一起的最佳方法,最好是使用 shell 脚本,但我一直坚持如何为两个单独的模式 grep 输出,同时理想情况下,仍然将所有 stdout/stderr 消息流式传输到命令运行时的终端。我想知道是否应该放弃在 shell 脚本中执行此操作的想法,而是编写一个小的 Python 脚本来执行此操作。
听起来像是一份工作tee
:
build | tee /some/file
ami_name=$(do_something_to /some/file)
deploy "$ami_name"
Run Code Online (Sandbox Code Playgroud)