[thelist] Server log retrieval & storage
Hugh Blair
hblair at bigfoot.com
Wed Aug 2 21:45:44 CDT 2000
Wow, Thanks. I'll dig through the code and make the mods to match my site.
Let's hope I don't have to bug you directly for too many questions.(grin) Here's
the only one I have right now.(grin)
Because of the evil linebreak, I'm not too sure how the "cronfile" line(s)
should read. Could you resend them and mark where lines start - or somehow give
me a hint? I think it's only two lines but I'm not sure. Thanks.
Very much appreciated. I'll share this whenever someone asks.
-Hugh
> -----Original Message-----
> [mailto:thelist-admin at lists.evolt.org]On Behalf Of CDitty
> Subject: Re: [thelist] Server log retrieval & storage
>
> I have you one better. I had a need for this about a year ago. Someone
> helped me write it and now I will pass it on to the list. I have it run
> daily, but there is no reason you couldn't run it weekly/monthly.
>
> #!/usr/bin/perl
> # A shell script to rename/archive and move the access logs
>
>
> # Settings
> $basepath = "FULL PATH TO STATS DIRECTORY HERE";
> $savepath = "FULL PATH TO STATS ARCHIVE DIRECTORY HERE";
> $filename = "access_log";
>
>
> @date = localtime(time); #puts the current time/date into an array
> $day = $date[3] + 1; #have to add 1 since it returns days
> starting at 0
> $month = $date[4] + 1; #same with the month
> #$yr = "20" . $date[5]; #only returns a 2 digit year, change 19 to 20
> after y2k
>
> if ($date[5] > 99) {
> $yr = 1900 + $date[5];
> } else {
> $yr = "20" . $date[5];
> }
>
> $today = $month . $day . $yr; #create a string of today's date
>
>
> $newname = $filename . $today . ".gz"; # create name for new file
>
>
> system("/usr/contrib/bin/gzip " . "$basepath/$filename"); #gzip the
> access_log, now have access_log.gz
>
>
> #chdir($basepath); # have to change to the directory that the access_log
> is in to rename it
> rename("$basepath/$filename.gz", "$basepath/$newname"); #renames
> access_log.gz to access_log08111999.gz or whatever
>
>
> #if you are putting the gzipped log in another directory
> system('mv', "$basepath/$newname", $savepath); #move to the
> archive directory
>
> print qq~
> $filename file compressed and moved to archive directory.
>
> Download at - PUT YOUR WEB URL HERE/$newname
> ~;
>
>
> This is the line I have in my cronfile.
> 55 23 * * *
> /usr/home/redhot/usr/local/etc/httpd/htdocs/sweeps1/cgi-local/log_archiver.p
> l | /usr/bin/mail -s "Stats Archived - Red Hot Sweeps"
> webmaster at redhotsweeps.com
>
> This emails the output to me and I just download it at will.
>
> CDitty
More information about the thelist
mailing list