Skip to content

Instantly share code, notes, and snippets.

@ramiroencinas
Created February 13, 2022 16:39
Show Gist options
  • Select an option

  • Save ramiroencinas/c871f8ab65bbb23ed272fc935c9fb1f4 to your computer and use it in GitHub Desktop.

Select an option

Save ramiroencinas/c871f8ab65bbb23ed272fc935c9fb1f4 to your computer and use it in GitHub Desktop.
my $path_logs = '/var/log/gifts/';
my $main_log = 'deliveries.log';
my $path_main_log = $path_logs ~ $main_log;
my $max_size_log = 20000000;
my $max_logs = 5;
exit unless $path_main_log.IO.e;
exit if $path_main_log.IO.s < $max_size_log;
my @log_files = $path_logs.IO.dir.grep(/$main_log$ | $main_log\d+$/).sort;
@log_files.pop.unlink if @log_files.elems == $max_logs;
for @log_files.kv.reverse -> $file, $idx { $file.rename($path_main_log ~ $idx + 1); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment