Xref: utzoo news.admin:4105 news.software.b:1771
Path: utzoo!utgpu!watmath!clyde!skep2!wcs
From: wcs@skep2.ATT.COM (Bill.Stewart.[ho95c])
Newsgroups: news.admin,news.software.b
Subject: Re: Auto-expiration of news
Message-ID: <293@skep2.ATT.COM>
Date: 30 Nov 88 02:13:00 GMT
References: <1066@psuhcx.psu.edu>
Reply-To: wcs@skep2.UUCP (46323-Bill.Stewart.[ho95c],2G218,x0705,)
Organization: AT&T Bell Labs Center 4632, Holmdel, NJ
Lines: 76

In article <1066@psuhcx.psu.edu> wcf@psuhcx (Bill Fenner) writes:
> Does anyone have a good way to expire news automatically when the news
> partition gets full?  We only have a 25 meg partition for news, and it

Here's my "trashnews" script.  I run it hourly from cron, which
seems to be often enough.  It uses "df" to find how many blocks
are free, and if there aren't enough, it grinds through the
history file looking for articles to trash (starts at the top,
works down - it doesn't care when the article *should* have expired.)

Caveats:
- You need to be running a version of news with one history file.
- If your "df" output format is different than System V you
	will have to modify the sed / awk script to pick out
	the right field.
- it doesn't clean up the history file - expire will have to do
	this for you.  I run expire -r weekly.

========================  cut here ============================================

####### Zap netnews until disk space is adequate. 
TARGET="/usr/spool"
remove="rm -f"	## remove="echo" for debugging
debug=":"	## debug="echo"

SPOOLDIR=/usr/spool/news	## Where the articles live
LIBDIR=/usr/lib/news		## Where the data files live
trashgroups="comp/mail/maps comp/binaries/atari talk/politics/misc comp/sys/atari"
					## attack these brutally

cd $SPOOLDIR	## Where the articles live

echo "===================== `date`"
limit=5000
export limit LIBDIR remove debug
if [ "$1" = "-x" ] ; then set -x ; remove="echo remove"; debug=echo ; shift ; fi
case "$1" in
	[0-9]*)	limit=$1 ; shift ;;
	esac

######## Make sure $TARGET has inodes (evil System V bug!)
if df $TARGET | sed 's/(/ (/' |
	awk ' { { print "df inodes ", $0 ; if ( $5 < 1000 ) exit 0 ; else exit 1 ; } } ' #>/dev/null
then echo trashing inodes ; find comp/mail/maps  -type f -print | xargs $remove ; find control talk rec/humor -type f -mtime +3 -print | xargs $remove
else echo inodes ok
fi

######## Make sure $LIBDIR has space
if df /usr | sed 's/(/ (/' |
	awk ' { { print "df,limit ", $3, '$limit' ; if ( $3 < '$limit' ) exit 0 ; else exit 1 ; } } ' #>/dev/null
then echo remove /usr/lib/news/ohis* /usr/lib/news/olog* ; $remove /usr/lib/news/ohis* /usr/lib/news/olog*
else echo /usr ok
fi
###############

(	## generate list of files to trash
#echo $LIBDIR/olog* $LIBDIR/ohistory 
find $trashgroups -type f -mtime +2 -print 2>/dev/null
sed -e 's/.*	//' -e '/^$/d' -e '/cancel/d' -e 's/\./\//g' $LIBDIR/history
) | while read victim victims ; do
	if [ -f "$victim" ] ; then
		if df $TARGET | sed 's/(/ (/' |
			awk ' { { print "df,limit ", $3, '$limit' ; if ( $3 < '$limit' ) exit 0 ; else exit 1 ; } } ' #>/dev/null
		then echo remove $victim $victims ; $remove $victim $victims
		else echo enough ; break
		fi
	else $debug $victim already gone
	fi
done
#################################### cut here ################
exit 0
-- 
#				Thanks;
# Bill Stewart, AT&T Bell Labs 2G218 Holmdel NJ 201-949-0705 ho95c.att.com!wcs
#
#	One Bell System - it works!