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

Smoot Carl-Mitchell smoot at tic.com
Wed Apr 22 20:49:31 UTC 2009


On Wed, 2009-04-22 at 22:01 +0200, Loïc Grenié wrote:

> > 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()" :

I do not think so.  The awk command is correct.  The problem is the mail
command is waiting for an EOF on the input pipe.  Try this:

awk -W interactive ' /192.168.1.100/ {  printf "%s\n.\n" $0 | "strace mail -s \"Some Subject\" me at email.address  "}'

mail terminates the message body with a line with a single period
character. This also adds a Subject: line to each message.  Note the
escaped double quote marks.

-- 
Smoot Carl-Mitchell
Computer Systems and
Network Consultant
smoot at tic.com
+1 480 922 7313
cell: +1 602 421 9005




More information about the ubuntu-users mailing list