I have two commands,
deploy. Currently I run
build manually, parse its output using my own eyes, and use a value I find in the output as an argument to
deploy. The process looks something like:
$ 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 ...
build is actually Packer, for the astute)
I would like to tie these two steps together in a script. The rough outline would include the following:
- Make sure the exit status was
0and that the output contained the string "AMIs were created", otherwise abort
- Extract the AMI number (
ami-19601070) from the output
I'm trying to come up with the best way to connect everything together, ideally by using a shell script, but I'm stuck on how to grep the output for two separate patterns while, ideally, still streaming all stdout/stderr messages to the terminal as the commands run. I'm wondering if I should abandon the idea of doing this in a shell script and instead write a small Python script to do it.