Linked Questions

Popular Questions

I'm working on a script which need to detect the first call to FFMPEG in a program and run a script from then on.

the core code was like:

strace -f -etrace=execve <program> 2>&1 | grep <some_pattern> | <run_some_script>

The desired behaviours is, when the first greped result comes out, the script should start. And if nothing matched before <program> terminates, the script should be ignored.

The main problem is how to conditionally execute the script based on the grep's output and how to terminate the script after the program terminates.

I think the first one could be solved using read, since the greped text are used as signals, its contents are irrelevant:

... | read -N 1 && <run_some_script>

and the second could be solved using broken pipe mechanism:

<run_some_script> > >(...)

but I don't know how to make them work together. Or is there a better solution?

Related Questions