in reply to Rotate log files based upon disk percentage full?

I am pretty sure that there must be some modules that do that (or at least part of that task). If not, I think it can be done easily in pure Perl in a few dozens of code lines at most. You need to sort your log files by date into an array and remove the oldest entries until you get below the threshold. I would be glad to offer some basic code if you gave some more details on the directory hierarchy where your files are stored.
  • Comment on Re: Rotate log files based upon disk percentage full?

Replies are listed 'Best First'.
Re^2: Rotate log files based upon disk percentage full?
by Anonymous Monk on Feb 07, 2014 at 00:17 UTC
    sub rotate_logs { my @files = target_files_by_date_in_dir( ... ); my $cent = size_in_percentage( \@files ); print "# size_in_percentage is $cent\n"; while( $cent > 80 ){ my @ten = splice @files, 0, 10; ## should be path()s already but just in case for my $file ( @ten ){ print "# removing oldest $file\n"; path( $file )->remove; } $cent = size_in_percentage( @files ); } print "# size_in_percentage is $cent\n"; } sub target_files_by_date_in_dir { use Path::Tiny; map { $$_[0] } sort { $$b[1] <=> $$a[1] } map { [ $_, $_->stat->mtime ] } map { path( $_ )->children } @_ } sub size_in_percentage { use Capture::Tiny; my( $files ) = @_; my ($du_stdout, $du_stderr, $df_exit) = capture { system( 'du', ..., @$files ); }; my ($df_stdout, $df_stderr, $df_exit) = capture { system( 'df', ... ); }; ... # math return $size; }