Rebuild a .newsrc file
Wm E Davidsen Jr
davidsen at crdos1.crd.ge.COM
Wed Oct 3 05:20:44 AEST 1990
Someone asked about rebuilding a .newsrc file. I have often wanted to
build one from scratch which wouldn't take me all day. I started
thinking about it and knocked out this little shell script which build a
file.
This subscribes to everything and allows you to mark things new in the
last N days as unread. I find it a lot less painful to type 'u' than to
have to add each group by hand.
This script is SLOW. I didn't put much effort into making it fast,
because the ability to read the recent articles requires a scan of the
whole spool directory (or database, and that's no fun in shell).
#!/bin/sh
# rebuild .newsrc
# - all groups will be subscribed
# - articles for the last three days will be marked unread
# (or use options to pick another date)
#
# author: Bill Davidsen - Oct 2, 1990
# initial values
SPOOLDIR=/usr/spool/news
AGE_LIMIT=3
LIBDIR="/usr/lib/news"
# look for arguments
# -aNN is age in days
# -sXXX is alternate spool directory
# -lXXX is alternate dir for active file
while [ $# -gt 0 ]
do case $1 in
-s) SPOOLDIR=$2
shift;shift
;;
-s*) SPOOLDIR=`expr $1 : '..\(.*\)'`
shift
;;
-a) AGE_LIMIT=$2
shift;shift
;;
-a*) AGE_LIMIT=`expr $1 : '..\(.*\)'`
shift
;;
-l) LIBDIR=$2
shift;shift
;;
-l*) LIBDIR=`expr $1 : '..\(.*\)'`
shift
;;
*) echo "Unknown option: $1"
exit 1
;;
esac #
done #
# pipe the directory names into a loop to build the values
cd $SPOOLDIR
SELECT="-type f -name '[1-9]*' -mtime -${AGE_LIMIT}"
sed 's/ .*$//' ${LIBDIR}/active | tr '.' '/' |
while read newsgroup
do # drop any group starting with .
char1=`expr "$newsgroup" : '\(.\).*'`
[ -z "$char1" -o "$char1" = "." ] && continue
[ ! -d $newsgroup ] &&
{ # just the group name, nothing read
echo "$newsgroup:" | tr '/' '.'
continue
}
file1=`eval find $newsgroup ${SELECT} -print | sort -n | head -1`
[ -z "$file1" ] &&
{ # just the group name, nothing read
echo "$newsgroup:" | tr '/' '.'
continue
}
file1=`basename $file1`
last1=`expr $file1 - 1`
echo "$newsgroup: 1-$last1" | tr '/' '.'
done #
--
bill davidsen (davidsen at crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen)
VMS is a text-only adventure game. If you win you can use unix.
More information about the Comp.unix.shell
mailing list