#! /usr/bin/perl -w ## dhlogs.pl ## pod at tail use strict; use Date::Calc qw(Today Add_Delta_Days); use LWP::UserAgent; print "\n Fetching log...\n\n"; my $yesterday = Yesterday(); my @msg = Main( 'joe@modem.com', # remote domain 'yosef', # remote id 'secret', # remote password "access.log.$yesterday", # remote logfile input 'c:/logs', # local dir to write to 'access.log', # local logfile output ); print "$_\n" for(@msg); sub Main { my ($dom, $id, $pw, $logweb, $logdir, $loglocal) = @_; die $! unless (-d $logdir && -w _); my $proxy = 'http://host.dom:port'; my $proxyuse = 1; my $url = "ftp://$id:$pw\@$dom/logs/"; my $ua = new LWP::UserAgent; $ua->proxy(['http', 'ftp'] => $proxy) if ($proxyuse == 1); $url = new URI::URL("$url/$logweb"); my $req = new HTTP::Request "GET" => ("$url"); my $res = $ua->request($req); if ($res->is_success) { my $rescont = $res->content; open OUT, "> $logdir/$loglocal" or die $!; print OUT $rescont or die $!; close OUT or die $!; my @return = ( " Program run successful\n", " Website: $dom", " Web log: $logweb", " Local dir: $logdir", " Local log: $loglocal\n", ); } else { my $resmsg = $res->message; } } sub Yesterday { my $Dd = -1; my($ty, $tm, $td) = Today(); my($yy, $ym, $yd) = Add_Delta_Days($ty, $tm, $td, $Dd); my $yesterday = sprintf "%04d-%02d-%02d", $yy, $ym, $yd; } END { print " Date::Calc $Date::Calc::VERSION\n", " LWP::UserAgent $LWP::UserAgent::VERSION\n", " Perl $]\n", " OS $^O\n", "\n"; my $stayopen = 0; # 0 is no, 1 is yes my $closedelay = 5; # seconds to wait before closing window if ($stayopen == 1) { print "\n Hit to exit\n\n"; ; } else { print "\n This window will close in $closedelay seconds...\n"; sleep $closedelay; } } =head1 NAME dhlogs.pl =head1 DESCRIPTION Automate fetch of yesterday's DreamHost web logfile =head1 SYNOPSIS dhlogs.pl No arguments or options - all params set in code =head1 TESTED ActivePerl 5.6.1-631 Windows 5.0.2195 sp2 (Win2k pro) Date::Calc 5.0 LWP::UserAgent 1.77 =head1 UPDATE 2002-03-18 20:05 CS Check for write perms in logdir sub Main{ ... } Test with ActivePerl launching from icon and from command-line 'print' instead of 'warn' in END{...} 2002-03-16 21:50 CST Test on Win2k against Inet-accessed FTP+Apache access log Test on Win2k against local Debian FTP+Apache access log Debug LWP::UserAgent FTP w/proxy Leading-zero pad Yesterday() return value via sprintf Reduce number of global vars {...} blocks subamify find yesterday's date, return @yesterday END{...} instead of &e2e() Variableize dom, id, pw Date::Calc snippet for yesterday's date Pause after (success|failure) 2002-03-13 Initial working code =head1 TODO Runlog along with print to console Test on Cygwin against Inet-accessed FTP+Apache access log Test on Debian against Inet-accessed FTP+Apache access log Test on big brudder's Win98 box =head1 AUTHOR ybiC =cut