I'm sure there are better ways, but the following seems to work:
#!/usr/bin/perl -w
use strict;
use Getopt::Long;
my $line;
my $NUM;
my $FILE;
GetOptions("f=s" => \$NUM, # -f=/var/log/messages
"n=s" => \$FILE); # -n=30
if (!($NUM)) {
$NUM = 20;
}
my @TailFile = `tail -$NUM $FILE`;
foreach $line (@TailFile) {
chomp $line;
print "$line\n";
}
Update: My comments were flip-flopped. Corrected.
If things get any worse, I'll have to ask you to stop helping me. |