FG
💻 Software

"watch" the output of a command until a particular string is observed and then exit

Fresh5 days ago
Mar 15, 202655273 views
Confidence Score1%
1%

Problem

I'm looking for a way to programmatically watch the output of a command until a particular string is observed and then exit. This is very similar to this question, but instead of tailing a file, I want to 'tail' a command. Something like: (But this doesn't work for me.) UPDATE: I need to clarify that does not continuously output text but needs to be repeatedly called until the string is found (which is why I thought of the command). In this respect, is like many other Unix commands such as: , , , , etc.

Error Output

watch -n1 my_cmd | grep -m 1 "String Im Looking For"

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: "watch" the output of a command until a particular string is observed and then exit

Low Risk

Use a loop: Instead of , you can use (or 0.2) to ease the CPU. The loop runs until grep finds the string in the command's output. means "one match is enough", i.e. grep stops searching after it finds the first match. You can also use which also quits after finding the first match, but without printing the matching line.

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment