www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] Webalizer & Cronjobs

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Location
    Insanity
    Posts
    1,131

    resolved [RESOLVED] Webalizer & Cronjobs

    I have webalizer2.0 installed.

    I tried setting up a cronjob that ran once an hour but all I get is an email tlling me that the job failed.

    Webalizer :-
    Running the Webalizer
    ---------------------

    The Webalizer was designed to be run from a Unix command line prompt or
    as a cron job. There are several command line options which will modify
    the results it produces, and configuration files can be used as well.
    Errrrmmmm.... I would disagree at this point on the claim that it runs as a cron job. The cronjob was set and reports a success in setting the job but all I get is an email with the error:-

    Died at /home/sites/{****.***.**}/public_html/stats/index.cgi line 15.

    and looking at the index.cgi script line 15 says :-
    die
    this is par of a conditional
    Code:
    if($cwd=~m#^(/home/(?:sites|cluster-sites/\d+)/[\w\.\-]+/)#) {
    	$root_path=$1;
    } else {
    	die
    }
    So I assume that the cronjob is failing because of this conditional.

    Any ideas on how to get this webalizer running as the help, FAQ's and help site do not cover this. Going to the help forum, it does not exist. The other help is on a yahoo groups page which I have not heard anything from in a few days.

    The full CGI is
    Code:
    #!/usr/bin/perl -w
    use strict;
    use BSD::Resource;
    setrlimit(RLIMIT_AS, 128000000, 1280000000);
    setrlimit(RLIMIT_CPU, 120, 120);
    use CGI;
    use Cwd 'getcwd';
    use IO::Handle;
    STDOUT->autoflush(1);
    my $cwd=getcwd();
    my $root_path;
    if($cwd=~m#^(/home/(?:sites|cluster-sites/\d+)/[\w\.\-]+/)#) {
    	$root_path=$1;
    } else {
    	die
    }
    
    my $cgi=new CGI;
    %ENV=(PATH=>'/bin:/usr/bin:/usr/local/bin', HTTP_HOST=>$ENV{HTTP_HOST});
    my $pid=open(CHILD, "-|");
    die unless defined $pid;
    if(!$pid) {
    	# child
    	
    	# Get the mtime of webalizer.current for later...
    	my $current_mtime;
    	my @cstat=stat("webalizer.current");
    	if(@cstat) {
    		$current_mtime=$cstat[9];
    	} else {
    		$current_mtime=0;
    	}
    	#
    
    	my %files;
    	my @poss_files=<$root_path/logs/*-access_log{,.*}>;
    	for my $poss_file (@poss_files) {
    
    		my $sort_fn=join "", reverse split(//, $poss_file);
    		$sort_fn=~s/^(zg|2zb)\.//; # Ignore compression stuff
    		$sort_fn=~s/^(\D)/0.$1/; # Make sure all are numbered.
    
    		# Use timestamp for emergency sort order
    		my @stat=stat($poss_file);
    		next unless @stat;
    		$sort_fn.=".$stat[9]";
    
    		# Don't bother looking at obviously-unchanged files
    		next if $stat[9]<$current_mtime;
    
    		$files{$sort_fn}=$poss_file;
    	}
    	# We want high-numbered ones first
    	for(reverse sort keys %files) {
    		system("webalizer","-D", "dns.cache","-n", $ENV{HTTP_HOST}, $files{$_});
    	}
    	exit 0;
    }
    local $/=undef;
    my $data=<CHILD>;
    close CHILD;
    if($data) {
    	print STDERR $data;
    }
    print $cgi->redirect("index.html");
    What would I need to do to stop this CGI from stopping at line 15.

    The webalizer is a one click install through the web host CP, I have no access to the routine other than the web interface. As this routine is running every hour as asked, it would be the index.cgi thats the issue.

    Any ideas?

  2. #2
    Join Date
    Jan 2009
    Location
    Insanity
    Posts
    1,131
    Well I found a yahoo egroup for webalizer, posted my problem and now have my answer direct from the author who replied on his personal account but not via the web forum... suspect, very suspect:-
    ======================================================
    Re: [webalizer] Need to cronjob the webalizer
    Tuesday, 7 April, 2009 1:06 AM
    From: "Bradford L. Barrett" <brad@mrunix.net>
    To: "Mark" <**********@yahoo.co.uk>

    This really has nothing to do with the Webalizer.

    --
    On Mon, 6 Apr 2009, Mark wrote:
    ======================================================
    Some help eh! What is it with rubberwalling people? Its not as if I went in to the forum and slated the software, I pointed out the issue which simply is this....

    A HTTP request results in the expected display of webstats.

    The Cronjob request which is server-side results in an email that states that the process died on line 15.

    Now you do not need to be a rocket scientist to work out that the cronjob is running and that the webalizer is the problem.

    The problem IMHO like most programming, lacks forethought to the end user and assumes too much in the way of you have 100% access to the commandline.

    For obvious security reasons the host does not allow direct commandline access but uses the extencp to help configure various requirements on the server.

    Anyone here know how to read and write PERL regular expressions, as I feel that this is where the issue is and why it is resulting in a "die" at the conditional here:-
    Code:
    if($cwd=~m#^(/home/(?:sites|cluster-sites/\d+)/[\w\.\-]+/)#) {
    	$root_path=$1;
    } else {
    	die
    }
    So any webalizer users who know PERL, got any ideas?

  3. #3
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    Looks to be testing if $cwd is a path starting /home/ then one of bits in brackets(not sure what the ? means at the start...) where \d+ means any number of digits(eg 1 or 00950 but not 1.4), followed by any combo of word characters, full stops or hyphens, ending with a /
    Then if it does match it assigns this path up to and including the / in $root_path.

    Is there any way you can output $cwd so you can manually check it(output to file maybe)?

  4. #4
    Join Date
    Jan 2009
    Location
    Insanity
    Posts
    1,131
    I don't know to be honest as this appears to be an issue that only allows a http request.

    My web host has suggested some method, I went to look and couldn't find the "tool" they were refering to.

    I tried what they suggested and no have the index.cgi in the cronjob path but this ended in an email saying
    Code:
    nice: /home/sites/{****.***.**}/public_html/stats/: Permission denied
    TBH, I am surprised at webalizer, regardless of the fact its free software, it seriously lack what I call credible support. I have had more support from my web host and from here than from Mr Unix as he calls himself.

    I shall try your suggestion of obtaining the $cwd string, which should be /home/sites/{****.***.**}/public_html/stats/ and see what is happening.

    If someone knows how to hard code this so it is not relying on being a dynamic script, it may prove to he a better option and solve the issue.

    I did ask the host if they could instal the PECL libray to add the http_get and http_request functions to make a http request but I think theyre not up for it and stated that the firewall prohibits http requests on the same machine. I guess this is to stop people from abusing the function.

    It is a head scratcher though, ho it works perfectly fine via an external http request but not from a server-cronjob and especially when the author claims runs as a cron job... I guess the author never bothered to read my post or comprehend it.

    Thanks for your reply.

  5. #5
    Join Date
    Jan 2009
    Location
    Insanity
    Posts
    1,131

    resolved

    Ok, to anyone who is curious...

    It is here for those who have hosts with similar setups, as each server and host has different operational requirements and policy, it is best to ask your host. But here is the method used to get around the problem.

    "Shell script"

    In a text editor put in the code and save as update.sh for example
    Code:
    #! /bin/bash
    cd /home/sites/domain.com/public_html/stats
    /usr/bin/webalizer -D dns.cache -nlocalhost -p -o . /home/sites/domain.com/logs/domain.com-access_log*
    and domain.com is the account domain of the account.

    this gets uploaded to your home folder (thats the folder that is 'domain.com' where public_html is visible) then chmod this update.sh to 755 which makes it executable by using an FTP client like filezilla or use PHP and write a script using the chmod() function, note that the correct way to use 755 in chmod is 0755 the 0 (leading zero) indicates octal, your path should be the whole path to the file your chmod-ing.

    When the file reads as an executable file, you set a cronjob routine to run the file you uploaded. This depends upon your setup or if you have a controlpanel that has it, the required settings to suit your needs. This automation removes the need to manually call the script to bring your stats update. The process is set to an hourly call to limit the work.

    Well it has proved to be an intresting journey...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles