Re: How Do I Keep Track OF the Files Being Downloaded From My Apache?
Hi,
I have a little perl script I made a while ago, takes the path of your logfile and, optionally an output file to write to; as command line arguments. Anyway, thought you might like to tinker with it, as you might be able to alter it for your specific needs.
------------------------
#!/usr/bin/perl -w
#$LOGFILE = "/var/log/apache2/access.log"; #uncomment this line is you have standard apache2 logging
open(LOGFILE, '<', $ARGV[0]) or die("Could not open log file.");
open(OUT, '>', $ARGV[1]) or die "Error: $!\n";
foreach $line (<LOGFILE>) {
$w = "(.+?)";
$line =~ m/^$w $w $w \[$w:$w $w\] "$w $w $w" $w $w (.+)/;
$site = $1;
$logName = $2;
$fullName = $3;
$date = $4;
$time = $5;
$gmt = $6;
$req = $7;
$file = $8;
$proto = $9;
$status = $10;
$length = $11;
$ident = $12;
%log = ("ip","$site","lname","$logName","name","$fullName","date","$date","time","$time","gmt","$gmt","request","$req","file","$file","prototype","$proto","status","$status","length","$length","ident",
"$ident");
print "\n$log{ip} , $log{date} , $log{time} , $log{request} , $log{file} \n\n $log{ident}\n";
print OUT "$log{ip}\n"; # this is where it decides what to print to the optional logfile, you may want
# to add $log{request} to show what they downloaded.
}
close(LOGFILE);
close(OUT);
------------------
lol, very painfully written, as you can see.. but it works!
On 7/8/07, KS <lists04@fastmail.fm
> wrote:
Orestes leal wrote:
>>
> In A Hurry, something more complex like this:
>
> cat /usr/local/apache2/logs/access_log | awk '{ print $1,$3,$4,$5,$7}'
>
> Later convert the output to HTML and put it in the web directory, so
> this is very basic but works for me.
>
That should work fine till a log rotate happens and you download counts
and other data will reinitialize. You will need some cache mechanism or
a temporary file to append your results and use that for HTML generation.
Take a look at awstats and Analog Stats while you are exploring Webalizer.
HTH,
/KS
--
To UNSUBSCRIBE, email to
debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
--
transiency.org
Attachment:
Tlog.pl
Description: Perl program
Reply to: