Hi guys,
I've just had a few spare minutes so decided to write a script that will read the last 10 lines of your error/web/ftp or any other log you have read access to, and display them to your browser.
I have seen a few posts from people who were interested in something like this so as I had a spare moment I thought I'd do it (I wanted it for myself also)
Here it is:
my $dir = "/PATH/TO/LOGS";
my $file = "web.log";
my $lastx = 10;
my ($i,$n) = 0;
@data=<FILE>;
close(FILE);
$i++;
}
foreach (@data) {
$n++;
next if ($n <= ($i - $lastx));
print "$_< br >";
}
}
my ($msg) = shift;
print header;
print $msg;
exit();
}The red variables are the only parts that need changing.
Obviously $dir is the path to the logs directory - no trailing slash.
$file is the name of the log file and $lastx is the number of the newest entries you want to view. So 10 shows the last 10 entries, 20 the last 20 entries etc...
Anyway hope you find it useful.
Oh, you'll also need to change < br > to a proper br tag.
I hate opening huge log files so this is perfect. It took about 1-2 seconds to load the last 10 entries of my 2.5MB web log.
Installations:http://www.wiredon.net/gt/
Favicon:http://www.wiredon.net/favicon/
I've just had a few spare minutes so decided to write a script that will read the last 10 lines of your error/web/ftp or any other log you have read access to, and display them to your browser.
I have seen a few posts from people who were interested in something like this so as I had a spare moment I thought I'd do it (I wanted it for myself also)
Here it is:
Code:
#!/usr/bin/perlCode:
use CGI qw(:standard);Code:
&main();Code:
sub main { my $dir = "/PATH/TO/LOGS";
my $file = "web.log";
my $lastx = 10;
my ($i,$n) = 0;
Code:
open(FILE,"<$dir/$file") || &error("Couldn't open $dir/$file : $!"); @data=<FILE>;
close(FILE);
Code:
foreach (@data) { $i++;
}
Code:
print header; foreach (@data) {
$n++;
next if ($n <= ($i - $lastx));
print "$_< br >";
}
}
Code:
sub error { my ($msg) = shift;
print header;
print $msg;
exit();
}
Obviously $dir is the path to the logs directory - no trailing slash.
$file is the name of the log file and $lastx is the number of the newest entries you want to view. So 10 shows the last 10 entries, 20 the last 20 entries etc...
Anyway hope you find it useful.
Oh, you'll also need to change < br > to a proper br tag.
I hate opening huge log files so this is perfect. It took about 1-2 seconds to load the last 10 entries of my 2.5MB web log.
Installations:http://www.wiredon.net/gt/
Favicon:http://www.wiredon.net/favicon/