#!/usr/bin/perl use strict; use warnings; # Pipe the output of tail -f open TAIL, "tail -f @ARGV |" or die "Failed to pipe to 'tail -f @ARGV' +. $!"; # Create a handle for SIGALRM that outputs a line of '=', 80 width. $SIG{ALRM}=sub{ printf "\n%s\n", '='x80; }; # Read from TAIL # Print output # Set the alarm timer to 2 seconds. # # By setting the alarm to 2 seconds with each line processed we can de +tect # the first 2 second silent period, and trigger $SIG{ALRM}. # After the alarm is triggered no further separators will be output un +til the # # This will not trigger multiple separator lines, since alarm will not + be reset # to 2 seconds until the next line is read. # print && alarm(2) while<TAIL> __END__ =head1 NAME tf - script for tailing a file and outputting a separator line when in +active =head1 SYNOPSIS tf /var/log/messages =cut
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: tf - tail a file and output separator line when inactive
by Hue-Bond (Priest) on Jul 18, 2006 at 17:06 UTC | |
by imp (Priest) on Jul 18, 2006 at 17:46 UTC | |
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 |