I often need to run different commands that would need to be re-run immediately after if the output contains a given string (status code is not enough).
Ideally the way to repeat it could be piped so I can easily use the logic to different commands.
e.g.
my_command -a | repeat_until_words
One approach I have in mind is to somehow store the output in a variable/file and do a search inside it, but I wonder if there is a better approach.
You could try something with a bash
while loop:
while my_command -a | grep 'foobar'; do true; done
0
I would write a bash function to achieve this, something like:
repeat_until_match() {
local command="$1"
local string="$2"
while true; do
output=$($command)
if [[ "$output" == *"$string"* ]]; then
break
fi
sleep 1
done
}
Then you can run it like this:
repeat_until_match "command you want to run" "words you want to match"