Here are the scripts:

update_awstats.pl
#!/usr/bin/perl -w # perl error reporting switches # -c = check the code for syntax errors # -w = "use warnings" and tells the interpreter to produce useful d +iagnostics # -T = "taint mode" which adds security internal to Perl # use strict; ###################################################### my $script_dir = "$ENV{'HOME'}/protected/cron/awstats"; my $db_website = "http://www.maxmind.com/download/geoip/database/"; my $db_gz_file = "GeoIP.dat.gz"; ###################################################### my $logfile = "$script_dir/GeoIP.dat.gz.log"; ###################################################### my $sh_gz_file = "update_geo-ip_db.sh"; my $sh_awstats = "update_awstats.sh"; use LWP::Simple; if (mirror("$db_website$db_gz_file", "$script_dir/$db_gz_file") != RC_ +NOT_MODIFIED) { # DB has been updated. Log the time and date of the update. &Write_Log; # Run the update_geo-ip_db.sh script to extract and replace the DB + file. chdir "$script_dir"; system("./$sh_gz_file"); } else { # DB already current, just update awstats chdir "$script_dir"; system("./$sh_awstats"); } sub Write_Log { use Fcntl qw(:DEFAULT :flock :seek :mode); # import + keywords for # flock, s +eek, and # chmod (w +hile strict # subs is +in use) my $time = gmtime(); my $file; open($file, "+< $logfile") or die "Can't open file: $!"; flock($file, LOCK_EX) or die "Can't establish file lock on file: $!"; my $checkfile = <$file>; chomp $checkfile; die "I am missing the log file!!!!" unless $checkfile; print $file "$time GMT\n"; close ($file); } exit 0;

update_geo-ip_db.sh
#!/bin/sh #################################################### # $HOME/protected/cron/awstats/update_geo-ip_db.sh # #################################################### # Extract and replace the GeoIP.dat DB file. # Set variables DB_DIR=$HOME/protected/db # Database directory DB_GZ=GeoIP.dat.gz # Gzipped DB file DB_PL=update_awstats.pl # DB Perl update script #################################################### # Script, no edit below this point. cp $DB_GZ $DB_DIR/$DB_GZ gunzip -f $DB_DIR/$DB_GZ # -f (force overwrite) perl $DB_PL exit 0

update_awstats.sh
#!/bin/sh ################################################## # $HOME/protected/cron/awstats/update_awstats.sh # ################################################## # Update AWStats. # Set variables AWSTATS_DIR=$HOME/www/path/to/awstats/ # AWStat +s directory AWSTATS_CMD="awstats.pl -config=www_yousite_com -update >/dev/null" + # AWStats update command line #################################################### # Script, no edit below this point. perl $AWSTATS_DIR$AWSTATS_CMD exit 0

I figure there are other monks who use AWStats and may find these scripts useful. I hope you will.

-Alexander

In reply to Cron update of AWStats and database for "country report" feature. by Alexander

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.