Suppose I have an executable which connects to an external machine and outputs a bunch of stuff to stdout over many minutes. At the end of that output there'll be a keyword such as "STOP", or the EOF character or something. After that keyword/EOF is printed the executable will sit there still executing but not sending any more output. It will not terminate by itself.
Now I want to pipe the output of this executable to a bash script that does this:
- Read what's being piped in and write it all to stdout.
- When you see the word "STOP" (or perhaps the character EOF), kill the executable.
I can use pkill to kill the executable. I could maybe use some combination of tee and grep, but I don't see how to do something once I get a match on the grep.