#!/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 diagnostics # -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, seek, and # chmod (while 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; #### #!/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 #### #!/bin/sh ################################################## # $HOME/protected/cron/awstats/update_awstats.sh # ################################################## # Update AWStats. # Set variables AWSTATS_DIR=$HOME/www/path/to/awstats/ # AWStats 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