/usr/share/doc/libnews-scan-perl/examples/empty-old is in libnews-scan-perl 0.53-3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #! /usr/local/bin/perl -w
use strict;
use Date::Parse;
sub usage {
"Usage: $0 age [dir]\n" .
"where:\n" .
" - age is the age in days\n" .
" - dir is the directory to scan (. by default)\n"
}
die usage unless @ARGV == 2 || @ARGV == 3;
my $age = shift;
my $dir = shift;
unless ($age =~ /^\d+$/) {
die "$0: age must be an integer\n";
}
$dir = '.' unless defined $dir;
opendir DIR, $dir or die "$0: opendir $dir: $!\n";
open SEEN, ">>$dir/.seen" or die "$0: open >>$dir/.seen: $!\n";
$/ = "";
my $file;
my $hdr;
my $path;
while ($file = readdir DIR) {
next if $file eq ".seen";
$path = "$dir/$file";
next unless -f $path;
if (-s _ == 0) {
print SEEN "$file\n" or warn "$0: print SEEN $file: $!\n";
unlink $path or warn "$0: unlink $path: $!\n";
next;
}
unless (open ART, $path) {
warn "$0: open $path: $!\n";
next;
}
$hdr = <ART>;
unless ($hdr =~ /^Date:\s+(.+)$/mi) {
warn "$0: $path: weird header: `$hdr'\n";
next;
}
close ART;
my $time = str2time($1) || 0;
if ($^T - $time >= $age * 86400) {
print SEEN "$file\n" or warn "$0: print SEEN $file: $!\n";
unlink $path or warn "$0: unlink $path: $!\n";
}
}
|