Re: OT: tail -f | while read
On Thu, Sep 06, 2001 at 09:47:01PM +0200, Martin F Krafft wrote:
> 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?
>
here you go :)
#!/usr/bin/perl
$| = 1;
while (<>)
{
chomp;
if (/something/i)
{
system("/usr/bin/program $_");
}
}
----
To use this call it like so
tail -f /var/log/messages | thisprog.pl
and you have your built in grep that supports regexs right there (in the /something/i line, just replace whats between the /'s)
the $_ var is the whole like as outputted from the STDIN that it matched on. Do that with what you want...
i think the reason as to why you were having problems is that grep itself didn't produce its output in the way you were expecting for a second pipe.
enjoy! :)
--
Adam McDaniel
Infrastructure Technology Consultant
M-Tech Mercury Information Technology, Inc.
Reply to: