Similar to this question, in Linux tcsh I want to tail a log file and when I match a regular expression I want to execute an arbitrary command. How can I do this?
|
feedback
|
|
In the poster's note a comment in that question leads to an SO post on disabling the auto-buffering when using pipes. The solution was to use unbuffer (from expect), as in:
wfaulk's answer (plus ayrnieu's cleanup) provides us with the script find-and-run:
Note 1: on Debian lenny, you'll need to install the "expect-dev" package; unbuffer is installed as "expect_unbuffer". Note 2: this is completely untested and Note 3: big thanks to ayrnieu for script completion and cleanup. | |||||||||||
feedback
|
|
This seems suited to a short perl script:
If you want to provide a pattern and a command with as flagged arguments, see the documentation at | |||||||||
feedback
|
|
In my case (on RHEL, I wanted But based on a blog post (http://www.smop.co.uk/blog/index.php/2006/06/26/tail-f-and-awk/) I've discovered that redirecting input from tail launched in a subshell did the trick:
This was not as simple, though. While working in an interactive shell, the same command, when run remotely using SSH, still froze as usual:
I've discovered that in this case, one must unbuffer tail's output using the unbuffer utility from Expect:
This must not be used on an interactive shell - unbuffer will cause an So the advice for you is that if the proposed solutions don't work, try launching BTW, see this article for thorough explanation of the output buffering problem: http://www.pixelbeat.org/programming/stdio_buffering/ | |||
|
feedback
|
|
A different approach is to use a program like swatch. Swatch is built to do exactly what you are talking about, plus a dozen other things. | |||
|
feedback
|