awk : actively tail a file & email when criteria is met

Loïc Grenié loic.grenie at gmail.com
Wed Apr 22 20:40:00 UTC 2009


2009/4/22 Evuraan::ഏവൂരാന്‍ <evuraan at gmail.com>:
> 2009/4/22 Loïc Grenié <loic.grenie at gmail.com>:
>> 2009/4/22 Evuraan::ഏവൂരാന്‍ <evuraan at gmail.com>:
>>> Greetings..!
>>>
>>> this below works:
>>>
>>> tail -f /var/log/apache2/access.log | \
>>> nawk '/192.168.1.100/{ print $0 }'
>>>
>>> and this too:
>>>
>>>  tail -f /var/log/apache2/access.log | \
>>> awk ' /192.168.1.100/ { system ("mail -s \"This works\" me at email.address")}'
>>>
>>> but this below, does not work:
>>>
>>>  tail -f /var/log/apache2/access.log | \
>>> awk ' /192.168.1.100/ {  print $0 | "mail me at email.address  "}'
>>>
>>> I tried nawk,gawk etc. still no go.
>>
>>    The line above is missing a "system()" :
>>
>> tail -f /var/log/apache2/access.log | \
>> awk ' /192.168.1.100/ {  print $0 | system("mail me at email.address  "); }'
>>
> thanks for the reply,  but thats does not quite help though.
>
> nothing happens until i send a ctrl-c, and then it says,
> sh: 0: not found

     Yeah, sorry: I should have checked before replying...

>>    Does it solve your problem ? Otherwise, could you specify exactly
>>  what is your problem ? (Command does not start, e-mail received
>>  is incorrect, etc...)
>
> the emails I recieved does not have txt that shud be the $0 of awk.

    Here it seems to work, however the mail is sent only when the input
  is closed (not one per line). Maybe that's your problem...

       Hope this helps,

              Loïc




More information about the ubuntu-users mailing list