: ########################################################################## # Shellscript: newsweekly - top news subjects # Version : 0.1 (beta) # Author : Heiner Steven (heiner.steven@odn.de) # Date : 11.06.1996 # SCCS-Id. : $Id: newsweekly.txt,v 1.1.1.1 1999/06/15 19:29:17 heiner Exp $ ########################################################################## # Description # ########################################################################## PN=`basename $0` # Program name VER='0.1 (beta)' : ${AWK:=nawk} : ${GREP:=egrep} : ${NEWSSPOOL:=/var/spool/news} Days=7 Top=5 # Top $Top subjects Threshold=3 Usage () { echo >&2 "$PN - top news subjects $VER (hs '96) usage: $PN [-n cnt] [-p days] [-m threshhold] -n: number of subjects to print for each newsgroup (default $Top) -m: minimum number of subjects (default $Threshold) -p: period (default is $Days days)" exit 1 } Msg () { for i do echo "$PN: $i" >&2 done } Fatal () { Msg "$@"; exit 1; } set -- `getopt hn:p:m: "$@"` while [ $# -gt 0 ] do case "$1" in -n) Top="$2"; shift;; -p) Days="$2"; shift;; -m) Threshold="$2"; shift;; --) shift; break;; -h) Usage;; -*) Usage;; *) break;; # First file name esac shift done set -u # DEBUG: no unset variables [ -d "$NEWSSPOOL" ] || Fatal "cannot read news spool directory: $NEWSSPOOL" Subjects=${TMPDIR:=/tmp}/nw$$ trap 'rm -f "$Subjects" >/dev/null 2>&1' 0 trap "exit 2" 1 2 3 13 15 cd "$NEWSSPOOL" find . -follow -type d -depth -print | sort | # Only get leaf directories $AWK ' { if ( !index ($0, LastDir) ) print LastDir LastDir = $0 } END { print LastDir } ' | while read Dir do ( cd "$Dir" Group=`pwd | sed -e "s:^$NEWSSPOOL/::" -e 's:/:.:g'` find . -type f -mtime -$Days -print | xargs $GREP '^Subject:[ ]' /dev/null | $AWK -F: '!Name[$1]++' | # Only the first subject of a file cut -d: -f3- | # Remove "name: Subject: ...." $AWK ' { sub (/^[ ]*/, "") sub (/[Rr][Ee]:[ ]*/, "") gsub (/[ ][ ]*/, " ") ++Subject [$0] } END { for ( Sub in Subject ) if ( Subject [Sub] > 1 ) print Subject [Sub] " " Sub } ' | sort -rn | head -$Top > $Subjects if [ `wc -l < "$Subjects"` -ge $Threshold ] then echo "$Group:" cat "$Subjects" echo fi ) done exit 0