From: hehehe on
Hello!

I`d like to know if its possible to do: tail -f test.log | grep
Exception
and when Exception appear script will be executed... any idea?

Regards


From: pk on
hehehe wrote:

> Hello!
>
> I`d like to know if its possible to do: tail -f test.log |
> grep
> Exception
> and when Exception appear script will be executed... any idea?

not with grep, but you can implement something like this

tail -f test.log | while IFS= read -r line; do
if echo "$line" | grep -q Exception; then
# do whatever here...
fi
done

From: hehehe on

Uzytkownik "pk" <pk(a)pk.invalid> napisal w wiadomosci
news:2413074.LiZASKD2KP(a)xkzjympik...
> hehehe wrote:
>
>> Hello!
>>
>> I`d like to know if its possible to do: tail -f test.log |
>> grep
>> Exception
>> and when Exception appear script will be executed... any idea?
>
> not with grep, but you can implement something like this
>
> tail -f test.log | while IFS= read -r line; do
> if echo "$line" | grep -q Exception; then
> # do whatever here...
> fi
> done
>


thx

From: Chris F.A. Johnson on
On 2010-05-27, pk wrote:
> hehehe wrote:
>
>> Hello!
>>
>> I`d like to know if its possible to do: tail -f test.log |
>> grep
>> Exception
>> and when Exception appear script will be executed... any idea?
>
> not with grep, but you can implement something like this
>
> tail -f test.log | while IFS= read -r line; do
> if echo "$line" | grep -q Exception; then
> # do whatever here...
> fi
> done

There's no need for grep:

tail -f test.log |
while IFS= read -r line; do
case $line in
*Exception*)
# do whatever here ...
;;
esac
done



--
Chris F.A. Johnson, <http://cfajohnson.com>
Author:
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)