1: #!c:/perl/bin/perl -w
2: # Windows doesn't have it
3: # Tail and grep program
4: #
5: use strict;
6:
7: my $file = $ARGV[0] || printUsage();
8: my $gs = $ARGV[1];
9: my $filesize = 0;
10:
11: open (FH,$file) || die "Unable to open $_: $!";
12:
13: seek (FH,0,2);
14: if (tell(FH) >=1500) {
15: seek(FH,-1500,2);
16: } else {
17: seek(FH,0,0);
18: }
19: while (1) {
20: while (<FH>) {
21: if ($gs) {
22: if ($_ =~ /$gs/o) {
23: print $_;
24: }
25: } else {
26: print $_;
27: }
28: }
29: seek(FH,0,1);
30: sleep (1);
31: }
32:
33: sub printUsage {
34: die "USAGE: ptail.exe <filename> [grep string]";
35: }
36:
37: =head1 NAME
38:
39: ptail.pl - A simple tail and grep program.
40: (I was working on NT at the time and needed this)
41:
42: =head1 SYNOPSIS
43:
44: ptail.pl <filename> [grep string]
45:
46: =head1 DESCRIPTION
47:
48: This is a goofy little tool helpful for tailing (and grepping) logfiles.
49:
50: =head1 AUTHOR
51:
52: bizzach, E<lt>wbs@lookiloo.netE<gt>
53:
54: =head1 SEE ALSO
55:
56: L<perl>.
57:
58: =cut