I run a program which writes a lot to stdout. After a certain time this program prints a defined line to stdout and I need to trigger this in order to call a function parallel (without terminating the first program).
How can I do this in bash?
A bit more explained: I need to run an installation program which is an executable from a mounted dvd1.iso. After some time it prints "Info: Eject DVD 1 and insert DVD 2 to continue.". And this is what shall be done automatically.
Following the answer here my test set up:
talker.sh
#!/bin/bash
for VAR in {1..20}
do
sleep 1s
echo "huhu $VAR"
done
listener.sh
#!/bin/bash
bash talker.sh \
| tee output.txt \
| grep --line-buffered "huhu 3" \
| ( while read -r line; do echo "found"; done; ) &\
tail -f output.txt
and how it works:
$ bash listerner.sh
huhu 1
huhu 2
huhu 3
found
huhu 4
huhu 5
...