403Webshell
Server IP : 216.92.14.13  /  Your IP : 216.73.216.171
Web Server : Apache
System : Linux vps4089.pairvps.com 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64
User : rmlac2fmr ( 1040637)
PHP Version : 8.2.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/local/bin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/local/bin/log_cat.pl
#!/usr/local/bin/perl
# $Id: log_cat.pl,v 1.5 2010/08/30 18:11:27 smk Exp $

use strict;
use Getopt::Long;
use Data::Dumper;
use Pod::Usage;
use Date::Calc;

=head1 NAME

log_cat.pl - Concatenate recent pair customer web log files

=head1 SYNOPSIS

log_cat.pl -u username -d domain_logname

  Options:
    -u username
    -d virtual domain logname
    -days N                   # cat only logs timestamped <= N days ago
    -mtime N                  # cat only logs with mtime <= N days ago
    -n                        # don't cat the logfiles, only print filenames
    -this_month               # Only send logs for this month 
    -ssl                      # use 'ssl_logs' directory
    -h help

  -mtime defaults to 90, and -days is 0.  
   Specifying 0 for days or mtime means "no limit."

  -this_month is useful with tools such as Webalizer, which rebuild
   logs a month at a time.  If you send a fixed number of days of
   logs, old months' reports will decay as they're fed fewer and fewer
   logfiles.  -this_month sends this month's logfiles only, if it's
   after the 3rd of the month, or this month's and last month's if
   it's the 3rd or earlier.

=cut

my $ZCAT = -e '/bin/zcat' ? '/bin/zcat' : '/usr/bin/zcat';

my %opt = (
	   days => 0,
	   mtime => 90,
	   );

GetOptions(\%opt, 
	   "uname|u|username=s", "domain|d=s", "help|h", 
	   "mtime=i", "days=i", "n", "this_month!", "ssl",
	   ) or pod2usage("Invalid option");

pod2usage(1) if $opt{help};
pod2usage( "You must supply a username" ) unless $opt{uname};
pod2usage( "You must supply a domain logfile name" ) unless $opt{domain};

my $domain = shift;

my @logfiles;

if ($opt{ssl}) {

    my $ssl_logs = "/usr/home/$opt{uname}/ssl_logs";

    # SSL log support.  Sanity check it. 
    if (!-d $ssl_logs) {
        pod2usage("$ssl_logs does NOT exist or is NOT a directory");
    }

    @logfiles = <$ssl_logs/$opt{domain}.*>;

} else {
    @logfiles = </usr/home/$opt{uname}/www_logs/$opt{domain}.*>;
}

# Only provide this month's logs
if ($opt{this_month}) {
    my ($y, $m, $d) = Date::Calc::Today;
    # Use previous month if today is the first.
    ($y, $m, $d) = Date::Calc::Add_Delta_YM($y, $m, $d, 0, -1) if $d < 4;
    
    my $month = sprintf("%04d%02d00", $y, $m);
    @logfiles = grep {/.(\d{8})(\.gz)?$/ and $1 >= $month } @logfiles;
}

# Filter log files by mtime
if ($opt{mtime}) {
    @logfiles = grep { -M $_ <= $opt{mtime} } @logfiles;
}

# Filter log files by filename datestamp
if ($opt{days}) {
    my $target = sprintf("%04d%02d%02d", 
		       Date::Calc::Add_Delta_Days(Date::Calc::Today, 
						  -$opt{days}));
    @logfiles = grep { /\.(\d{8})(\.gz)?$/ and $1 >= $target }
		       @logfiles;
}

foreach (sort @logfiles) {
    if ($opt{n}) {
	print "$_\n";
    } else {
	if ( /\.gz$/ ) {
	    open FILE, "$ZCAT $_ |" or die $!;
	} else {
	    open FILE, "< $_" or die $!;
	}
	
	print while <FILE>;
	close FILE;
    }
}

__END__

# $Log: log_cat.pl,v $
# Revision 1.5  2010/08/30 18:11:27  smk
# #25914: Search for zcat
#
# Revision 1.4  2008/10/29 16:11:00  smk
# #20593: update to handle ssl logs directory
#
# Revision 1.3  2004/06/01 18:23:22  alan
# Fix bug in log_cat.pl.  Tweak it to run before the 4th of the month so it fixes the problem the bug caused
#
# Revision 1.2  2004/05/12 17:00:59  alan
# #3266: add -this_month option
#
# Revision 1.1  2003/07/01 17:37:50  alan
# Add log_cat.pl with new days, mtime, n options
#

Youez - 2016 - github.com/yon3zu
LinuXploit