To overcome the stats problem i have written the following perl script.
The idea of this script is to check the time stamp of the stats index page i.e /home/steve/tmp/webalizer/index.html and calculate the difference days between file time stamp and the present server time stamp and update the stats if the difference is more than 2 days ( we can change this value ).
This script requires the Date::Calc module so first you need to check for that module and install it if it is not instlalled.
You can install it from WHM ->> Software ->> Install a perl module.
1) vi /rsanetworks/web.pl
#=======================================================================================================================
#
# Script to update the webalizer stats
#
# Author : Steve
#
# Date : 14/04/2006
#
#=======================================================================================================================
#!/usr/bin/perl
use warnings;
use strict;
use Date::Calc qw(Delta_Days); # to calculate the difference days between two dates
my %users;
open FH, ‘/etc/trueuserdomains’ or die $!;
while ( <FH> )
{
my @arr = split /:/;
$users{$arr[1]} = $arr[0];
}
while ( my ( $user, $domain ) = each %users )
{
chomp ( $user, $domain );
$user =~ s/^\s//;
$domain =~ s/^\s//;
my $file = “/home/$user/tmp/webalizer/index.html”;
$file =~ s/(\s)//;
if ( -e $file ) #checking whether previous stats have been generated
{
my $prev = ( stat ( $file ) )[9] ;
my ( $pd, $pm, $py ) = ( localtime ( $prev ) )[3..5]; #pd - previous date pm - previous month py - previous year
my ( $cd, $cm, $cy ) = ( localtime ( time ) )[3..5];
my $diff = Delta_Days( $cy, $cm + 1, $cd, $py, $pm + 1, $pd ); # we have added 1 to month to avoid 0 which is for Jan if ( $diff < -2 ) # if you want to change the difference days you can do it here but it should be nagative
{
chdir( “/usr/local/apache/domlogs” );
system ( “/usr/local/cpanel/3rdparty/bin/webalizer -N0 -D /home/$user/tmp/webalizer/dns_cache.db -R250 -p -n
$domain -o /home/$user/tmp/webalizer $domain > /dev/null 2>>error_stat.log ” );
}
}
else # No previous stats
{
chdir( “/usr/local/apache/domlogs” );
system( “/usr/local/cpanel/3rdparty/bin/webalizer -N0 -D /home/$user/tmp/webalizer/dns_cache.db -R250 -p -n
$domain -o /home/$user/tmp/webalizer $domain > /dev/null 2>>error_stat.log “);
}
}
# Script ends here
HOWTOs :: WHM/Cpanel Problems