Execute command when line matches
I'm monitoring a file with tail -f
tail -f <filename> |grep <string> what i want to do is to execute another script when grep finds a new match. Is there an event message that can be captured or some other method? |
Code:
if grep <string> filename 1>/dev/null; then |
Unfortunately, this seems to be an ever growing log file, so I don't think that would work because you'd have to know where you got to last time, then loop round and continue from that line num (not to mention logrotate issues).
I'd use http://search.cpan.org/~mgrabnar/Fil...0.99.3/Tail.pm instead, which is designed especially for this situation. |
Perhaps something like this...
Code:
while IFS= read var ; do |
This is working on my system using GNU grep.
Code:
tail -f <filename> | grep --line-buffered <string> | while read;do |
Or you could eliminate grep entirely.
Code:
while read -r; do |
All times are GMT -5. The time now is 11:10 AM. |