I have a pipeline where a long-running command feeds into a filter. If the filter finds "foo", I want the long-running command to die.

In general this is not possible, because sibling processes (two children of the same parent) do not have any knowledge of each other. But consider the following example and answers:

We'll assume the following pipeline, which uses Linux's inotifywait program:

   1 inotifywait -m --format '%e %f' uploads |
   2 while read -r events file; do
   3   if [[ $events = *MOVED_TO* ]]; then
   4     : do something special
   5     if [[ $file = *abort* ]]; then
   6       : special sentinel file found
   7       : want to kill the inotifywait process
   8     fi
   9   fi
  10 done

In this example, the user wants to stop the inotifywait program if a rename is performed with the resulting filename containing the string "abort". What are our options here?

BashFAQ/117 (last edited 2023-11-22 12:02:49 by geirha)