29
10
I'm looking for a way to programatically 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:
watch -n1 my_cmd | grep -m 1 "String Im Looking For"
(But this doesn't work for me.)
UPDATE: I need to clarify that 'my_cmd' does not continuously output text but needs to be repeatedly called until the string is found (which is why I thought of the 'watch' command). In this respect, 'my_cmd' is like many other unix commands such as: ps, ls, lsof, last, etc.
I would have thought it was possible to
tail -f
a program output just as well as a file... Am I wrong? – Joanis – 2012-01-06T00:52:00.230@Joanis. You're right, but in my case 'my_cmd' doesn't continuously produce output and must be repeatedly called (much like most commands: ps, ls, lsof, etc) – gdw2 – 2012-01-06T04:01:17.703