Change-Id: I46b3471e5ac6f0e026dfa1d1454e7b9eff9ec1bechanges/69/7569/7
parent
40e00631a2
commit
cfc4ae1e51
@ -0,0 +1,49 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Config::Any;
|
||||
use File::Find;
|
||||
|
||||
my $cfgs = Config::Any->load_files({files => ['/etc/ngcp-cleanup-tools/cdr-files-cleanup.yml'],
|
||||
use_ext => 1, flatten_to_hash => 1});
|
||||
if (!$cfgs || !values(%{$cfgs})) {
|
||||
die("no config found");
|
||||
}
|
||||
my %cfg = map {%{$_}} values(%{$cfgs});
|
||||
|
||||
($cfg{enabled} // 'no') =~ /1|yes/ or exit(0);
|
||||
|
||||
my $now = time();
|
||||
my $maxage;
|
||||
|
||||
for my $p (@{$cfg{paths}}) {
|
||||
$maxage = $p->{max_age_days} // $cfg{max_age_days};
|
||||
$maxage or next;
|
||||
$maxage *= 86400;
|
||||
my @paths = ($p->{path});
|
||||
if ($p->{wildcard} =~ /1|yes/) {
|
||||
@paths = glob($p->{path});
|
||||
}
|
||||
for my $path (@paths) {
|
||||
-d $path or next;
|
||||
finddepth(\&recurser, $path);
|
||||
}
|
||||
}
|
||||
|
||||
sub recurser {
|
||||
my $path = $File::Find::name;
|
||||
if (-d $path) {
|
||||
#print("directory: $path\n");
|
||||
rmdir($path); # ignore errors
|
||||
}
|
||||
elsif (-f $path) {
|
||||
#print("file: $path\n");
|
||||
my @sb = stat($path);
|
||||
@sb or return;
|
||||
my $age = $now - $sb[9];
|
||||
$age < $maxage and return;
|
||||
#print("delete: $path\n");
|
||||
unlink($path);
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
acc-cleanup.conf etc/ngcp-cleanup-tools/
|
||||
acc-cleanup.pl usr/sbin/
|
||||
cleanup-old-cdr-files.pl usr/sbin/
|
||||
ce/cleanup-tools etc/cron.d/
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
acc-cleanup.conf etc/ngcp-cleanup-tools/
|
||||
acc-cleanup.pl usr/sbin/
|
||||
cleanup-old-cdr-files.pl usr/sbin/
|
||||
moh-cleanup usr/sbin/
|
||||
elasticsearch-remove-old-indices usr/sbin/
|
||||
pro/cleanup-tools etc/cron.d/
|
||||
|
||||
Loading…
Reference in new issue