I got tired of tailing an error log and hitting enter several times to create a gap between requests, so I automated this behaviour.
This script will tail a file and print a line '='x80 whenever there is a 2 second silent period - but will not output multiple separator lines for long silent periods.
#!/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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.