Article View: news.software.readers
Article #48113Re: Automating Removal of Mailing List Mail With Slrn or Slrnpull
From: tsumme... tony summerfelt
Date: Mon, 19 Apr 1999 00:00
Date: Mon, 19 Apr 1999 00:00
102 lines
4135 bytes
4135 bytes
On 18 Apr 1999 04:36:12 GMT, John E. Davis wrote:
> slang script (use, e.g., the slsh program distributed with slang 1.3.5
now THIS is a true gem. i haven't really looked in the slang 1.3.5
directories beyond compiling it. i was wondering if something just like this
was possible with slang :)
it would be nice if this could be turned into a win32 executable...
> to just get a list of files older than 21 days. Use this at your own
> risk!
this is floating around on one or two linux distrubtions, it's in perl but
it will do pretty much the same thing...it's a little bit longer because it
checks for race conditions, but it's what i've been using here...
#!/usr/bin/perl
#
sub debug {
if($ENV{'DEBUG'}) { print STDERR $_[0],"\n"; sleep 0; }
}
sub dodir {
my(@dirlist,@dirlist1,$thisdir,$a,$mode,$mtime,$ctime,$atime,$thefile,
%skiplist,$dev,$ino,$thedev,$theino);
$thisdir=$_[0];
chdir($thisdir) || die("Couldn't change directories to $thisdir");
&debug("========== Starting $thisdir =============");
$thedev = $_[1]; $theino=$_[2];
($dev,$ino) = lstat(".");
if(($dev != $thedev) || ($ino != $theino)) {
die("Directory changed after cd: $thisdir");
}
do {
@dirlist = ();
opendir(THISDIR,".");
@dirlist1 = grep(!/^\.\.?$/,readdir(THISDIR));
closedir(THISDIR);
foreach $thefile (@dirlist1) { &debug("Dirlist1: $thefile"); }
foreach $thefile (keys %skiplist) { &debug("Skiplist: $thefile"); }
foreach $thefile(@dirlist1) {
if($skiplist{$thefile} != 1) {
push(@dirlist,$thefile);
} else { &debug("Didn't add ".$thefile." to dirlist"); }
}
if(scalar @dirlist <= 0) {
&debug("========== Ending $thisdir =============");
&debug("returned skiplist = ".scalar keys %skiplist);
chdir("..");
return(scalar keys %skiplist);
}
foreach $thefile (@dirlist) { &debug("Dirlist: $thefile"); }
foreach $thefile (shift(@dirlist)) {
(($dev,$ino,$mode,$a,$a,$a,$a,$a,$atime,$mtime,$ctime,$a,$a)
= lstat($thefile)) || die("Couldn't lstat $thefile");
SWITCH: {
if(-d $thefile) {
&debug("Removing directory $thisdir/$thefile");
if(&dodir($thefile,$dev,$ino) > 0) {
$skiplist{$thefile} = 1;
&debug("Put dir $thefile on skiplist");
} else {
&debug("Doing rmdir");
rmdir($thefile) || die("Couldn't remove dir:
$thisdir/$thefile");
&debug("Removed directory $thefile");
}
($dev,$ino) = lstat(".");
if(($dev != $thedev) || ($ino != $theino))
{ die("Directory changed after cd: $thefile"); }
last SWITCH;
}
if(time() > ($ctime+$age)) {
&debug("Removing $thisdir/$thefile with an atime of $atime");
unlink($thefile) || die("Couldn't remove file $thefile");
} else {
$skiplist{$thefile} = 1;
&debug("Put $thefile on skiplist");
}
}
}
&debug("Scalar dirlist = ".scalar @dirlist);
} while(true);
}
$age = shift(@ARGV) * 3600;
@topdirs = @ARGV;
die <<USAGE unless scalar @topdirs > 0;
Usage:
tmpwatch [maximum age, in hours] directory ...
Removes all old files in a directory, without any known race conditions.
USAGE
foreach(@topdirs) {
&debug("Top dir is $topdir");
($dev,$ino) = lstat($_);
&dodir($_,$dev,$ino);
}
Technical Details
Message-ID:
<slrn7hl163.l4.tsummerfelt1@co146453-a.kico1.wave.home.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp!not-for-mailReferences:
<924405383.479.38@news.remarQ.com> <slrn7hio99.u7q.davis@aluche.mit.edu>Show Full Headers
Complete Article Headers
Message-ID: <slrn7hl163.l4.tsummerfelt1@co146453-a.kico1.wave.home.com> Subject: Re: Automating Removal of Mailing List Mail With Slrn or Slrnpull Date: Mon, 19 Apr 1999 00:00:00 +0000 From: tsumme...@myspleenhome.com (tony summerfelt) References: <924405383.479.38@news.remarQ.com> <slrn7hio99.u7q.davis@aluche.mit.edu> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp!not-for-mail X-Deja-AN: 468133109 X-Complaints-To: ab...@home.net X-Trace: news1.rdc1.on.wave.home.com 924487707 24.226.18.124 (Sun, 18 Apr 1999 19:08:27 PDT) Organization: FIDONET - 1:249/139 User-Agent: slrn/0.9.5.4 (UNIX) Reply-To: tsumme...@myspleenhome.com NNTP-Posting-Date: Sun, 18 Apr 1999 19:08:27 PDT Newsgroups: news.software.readers,alt.lang.s-lang