: # *-*-perl-*-*
    eval 'exec perl -S $0 "$@"'
    if $running_under_some_shell;  

# find-expired-broker-objects.pl 
#
# usage: 
#
#      % cd /usr/local/harvest/brokers/mybroker
#      % find objects -type f -print | find-expired-broker-objects.pl > list
#      % vi list
#      % awk '{print $NF}' list | xargs rm
#

$now = time;

while (<>) {	# stdin is a list of filenames (eg from find)
	chop ($f = $_);
	next unless open f;
		$timestamp = 0;
		$ttl = 0;
	while (<f>) {
		$timestamp = $1
			if (/^Update-Time{\d+}:\t(\d+)/io);
		$ttl = $1
			if (/^time-to-live{\d+}:\t(\d+)/io);
		last if ($ttl != 0 && $timestamp != 0);
	}
	close f;
	$exp = $timestamp + $ttl;
	#print "Timestamp: $timestamp\n";
	#print "      TTL: $ttl\n";
	#print "  Expires: $exp\n";
	if ($exp < $now) {
		printf ("Expired %4.1f days ago %s\n",
			($now - $exp) / 86400, $f);
	}
}
	
