in reply to tf - tail a file and output separator line when inactive
Often I find myself doing tail -f file | grep --line-buffered "kernel" and your program has given me the inspiration to automate that. This is my version. It features taint mode and File::Tail:
#!/usr/bin/perl -T use strict; use warnings; use File::Tail; die "Not enough arguments\n" unless @ARGV; my ($file, $regex) = @ARGV; $regex = '.' unless defined $regex && length $regex; my $tail = File::Tail->new ( name => $file, maxinterval => 5, adjustafter => 10, ); $SIG{ALRM} = sub { printf "\n%s\n", '='x80; }; while (defined ($_ = $tail->read)) { print && alarm 2 if /$regex/; }
Let me anticipate that someone is going to reply talking about code interpolation in the regex:
# ~/bin/tf2.pl file '(??{print "Hello, world!\n"})' Eval-group not allowed at runtime, use re 'eval' in regex m/(??{print +"Hello, world!\n"})/ at /root/bin/tf2.pl line 20.
Update: Minor change according to imp's comment.
--
David Serrano
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: tf - tail a file and output separator line when inactive
by imp (Priest) on Jul 18, 2006 at 17:46 UTC | |
|
Re^2: tf - tail a file and output separator line when inactive
by ikegami (Patriarch) on Jul 18, 2006 at 17:09 UTC | |
by Hue-Bond (Priest) on Jul 18, 2006 at 17:38 UTC | |
by ikegami (Patriarch) on Jul 18, 2006 at 17:51 UTC | |
by Aristotle (Chancellor) on Jul 18, 2006 at 18:31 UTC |