GithubHelp home page GithubHelp logo

Comments (4)

richardforth avatar richardforth commented on June 5, 2024

Knocked out some test code that works:

#!/usr/bin/perl
use strict;

my $log_dir;
my $size;
$log_dir = "/var/log/";  # would need logic to set $log_dir based on distribution
$size = 1024; # this is bytes, I know, for testing only!


print "Scanning $log_dir for files larger than $size bytes....\n";
opendir(my $dh, $log_dir) || die "Can't open $log_dir: $!";
while (readdir $dh) {
  if ( -s >= $size ) {
    print "$_\n";
  }
}

from apache2buddy.

richardforth avatar richardforth commented on June 5, 2024

Test code committed to a test repository for ease of testing on different platforms, to develop the logic further

https://github.com/richardforth/perl_large_file_scanner/

from apache2buddy.

richardforth avatar richardforth commented on June 5, 2024

Working, next step is to merge into the main codebase of apache2buddy under staging.

from apache2buddy.

richardforth avatar richardforth commented on June 5, 2024

There is also a working function now in checkbox4 which is ready to port across (uses File::Find):

sub systemcheck_large_logs {
	my ($logdir) = @_;
	our $ymdhms;
        my $logfile = $logdir . "/" . $ymdhms . "_large_logs.log";
        unless (open(LOG_FILE, ">$logfile")) {
                die "Can't open log file $logfile for writing: $!\n"
        }
	info_print("Scanning /var/log for files larger than 1GB:");
	my $dir = '/var/log'; # whatever you want the starting directory to be
	my @logs;
	my $logfiles_raw = find(sub {push @logs, $File::Find::name  if -s >= 1024000000;},  $dir);
	foreach my $log (@logs) {
		chomp($log);
		my $size = -s $log;
		my $humansize = sprintf "%.2f", $size/1024/1024/1024;
		bad_print_item($log . " --> " . $humansize . "GB");
		print LOG_FILE $log . " --> " . $humansize . "GB\n";
	}
	if (@logs == 0) {
		good_print_item("No large logs files were found.");
	} else {
		bad_print("Consider setting up a log rotation policy.");
	}
}

from apache2buddy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.