Bob asks:

> Anyone know of a tool that will "prune" old rpms from a directory?  What I'm
> referring to is something that will cruise through the /usr/src/redhat/RPMS
> and /usr/src/redhat/SRPMS and remove all but the newest files.

Clay responds:

Perl is your friend. 

(NOTE: This is just an example I whipped up in a few minutes. I will not be
responsible for any data loss)

#!/usr/bin/perl

$dir=".";

opendir(DIR, $dir);
while (defined ($_=readdir(DIR))) {
	next unless /rpm$/;
	/^(\w+)/;
	$pre=$1;
	$files{$pre}{$_}=$_;
}

foreach $pre (sort keys %files) {
	$num = scalar keys %{$files{$pre}};
	foreach $file (sort keys %{$files{$pre}}) {
		$num--;
		print "Deleting $files{$pre}{$file}\n" if $num;
		unlink $files{$pre}{$file} if $num;
	}

}


There is a slight bug:

RPMs before perl script is run, notice only 1 "duplicate" package, 
frozen-bubble:

frozen-bubble-0.9.2-realtime.2.i386.rpm
frozen-bubble-0.9.3-realtime.1.i386.rpm
grustibus-0.43-realtime.3.i386.rpm
gtetrinet-0.4.1-realtime.4.i386.rpm
hylafax-4.1.2-realtime.2.i386.rpm
hylafax-htmldoc-4.1.2-realtime.2.i386.rpm
icebreaker-1.2.1-realtime.3.i386.rpm
kobodeluxe-0.4pre7-realtime.2.i386.rpm
lbreakout-010315-realtime.2.i386.rpm
lbreakout2-2.2.2-realtime.2.i386.rpm
nethack-3.4.0-realtime.4.i386.rpm
nethack-doc-pdf-3.4.0-realtime.4.i386.rpm
nethack-spoilers-3.4.0-realtime.4.i386.rpm
perl-SDL-1.12-realtime.1.i386.rpm
pysol-sound-server-2.50-realtime.1.i386.rpm
setiathome-3.03-realtime.4.i386.rpm

<script run>

Deleting frozen-bubble-0.9.2-realtime.2.i386.rpm
Deleting hylafax-4.1.2-realtime.2.i386.rpm
Deleting nethack-3.4.0-realtime.4.i386.rpm
Deleting nethack-doc-pdf-3.4.0-realtime.4.i386.rpm


Eeek!

Script is a little vicious. 
-- 
Minneapolis St. Paul Twin Cities MN        | Phone : (952)943-8700
http://www.mn-linux.org Minnesota Linux    | Fax   : (952)943-8500
Key fingerprint =  6C E9 51 4F D5 3E 4C 66 62 A9 10 E5 35 85 39 D9