Hier ist meine schnelle Lösung für dieses Problem:
Anwendungsbeispiele:
$ watch_and_kill_if.sh ERROR my_program
watch_and_kill_if.sh
#!/usr/bin/env bash function show_help() { IT=$(CAT <<EOF usage: ERROR_STR YOUR_PROGRAM e.g. this will watch for the word ERROR coming from your long running program ERROR my_long_running_program EOF ) echo "$IT" exit } if [ "$1" == "help" ] then show_help fi if [ -z "$2" ] then show_help fi ERR=$1 shift; $* | while IFS= read -r line do echo $line if [[ $line == *"$ERR"* ]] then exit; fi done if [ "$1" == "help" ] then show_help fi if [ -z "$2" ] then show_help fi ERR=$1 shift; $* | while IFS= read -r line do echo $line if [[ $line == *"$ERR"* ]] then exit; fi done