[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: tail -f | while read



On Thu, Sep 06, 2001 at 09:47:01PM +0200, Martin F Krafft wrote:
> also sprach John Patton (on Thu, 06 Sep 2001 02:33:01PM -0500):
> > I couldn't get a variation of that working either... but if
> > myprog is a perl script and is driven by the while(<>) loop,
> > then you should be able to just pipe the output of the grep
> > right into it, like so:
> > 
> >    tail -f /var/log/syslog | grep something | myprog

Why do that?  perl can do regular expressions; if you're going to fire
up perl firing up grep seems like a waste.
 
> > I'm not sure if that can be done directly with a shell
> > script though.
> 
> why not, what's the difference???
> 
> and could someone give me a perl one-liner that takes each such line
> fed into its STDIN, and for each line, calls an external shell script
> with the entire line as argument?

tail -f /var/log/syslog | perl -n -e '`myprog $_` if m/pattern/'

Note that it's usually safer to use system rather than backticks, but
as you requested this is a quick one-liner :)

-- 
Nathan Norman - Staff Engineer | A good plan today is better
Micromuse Ltd.                 | than a perfect plan tomorrow.
mailto:nnorman@micromuse.com   |   -- Patton

Attachment: pgpMiVAHIy_hN.pgp
Description: PGP signature


Reply to: