options:
-u<unitlen> <interval> is measured in units of <unitlen> seconds
(default is 86400, so <interval> is in days)
- -s<slop> allow kept items to be <slop> seconds shorter apart than
- specified; default is 10% of <unitlen>
- -n do not really delete
- -r recursive removal (rm -r)
+ -s<slop> allow kept items to be <slop> seconds shorter or
+ longer apart than specified; default is 0.1 unit
+ -n do not really delete
+ -r recursive removal (rm -r)
+ --help
example:
/home/ian/junk/expire-iso8601 14x1 4x7
uses units of 86400s (1 day) with a slop of 8640
0 ok
4 rm failed
8 bad usage
- 16 catastrophic failure
+ -1 catastrophic failure
END
use POSIX;
$|=1;
+our @oldfiles;
our @files;
our $rm = 1;
our $recurse = 1;
foreach my $f (<[0-9]*>) {
if ($f !~ m/^ \d\d\d\d - \d\d - \d\d
(?: T \d\d \: \d\d (?: \: \d\d )?
- (?: [-+] \d{1,2} \:? \d\d )? )? $/x) {
+ (?: [-+] \d{1,2} \:? \d\d )? )?
+ ( \.rm )? $/x) {
print STDERR "ignoring $f\n";
}
+
+ if ($1) {
+ push @oldfiles, $f;
+ next;
+ }
+
my @t = Date::Parse::strptime($f);
@t = map { $_ // 0 } @t;
my $t = mktime @t;
if ($rm) {
my $r= system 'rm', ($recurse ? ('-r') : ()), "--", $fn;
die "run rm: $!\n" unless defined($r) && $r >= 0;
- exit 12 if $r;
+ exit 4 if $r;
}
}
sub implement () {
+ foreach (reverse sort @oldfiles) {
+ printf "remove %s - old\n", $_;
+ do_rm($_);
+ }
foreach (reverse @files) {
next unless @{$_->{U}};
printf "keep %s for %s - age %.1f\n",