Chirp

For some applications and tools there can be no output for a long time. When these are tailed seeing nothing is disquieting. The following Perl script will output a "chrip" every few seconds, intermixed with the log file's content. For example,
tail -F foo.log | grep bar | chirp
Save the following to /usr/local/bin/chrip
#!/usr/bin/perl -w

use strict;
use POSIX qw(strftime);

$::timeout = 5;
$::format = "%F %T";

while ( @ARGV ) {
my $arg = shift @ARGV;
if ( $arg eq "-t" ) {
$::timeout = shift @ARGV;
}
elsif ( $arg eq "-f" ) {
$::format = shift @ARGV;
}
elsif ( $arg =~ /^-/ ) {
print "usage: chirp [ -t seconds ] [ -f strftime-pattern ]\n";
exit 1;
}
}

local $SIG{ALRM} = sub {
print strftime( $::format, localtime ), " chirp\n";
alarm $::timeout;
};

alarm $::timeout;

while ( <> ) {
print strftime( $::format, localtime ), " ", $_;
}

# END