Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site trwatf.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!trwatf!root From: root@trwatf.UUCP (Lord Frith) Newsgroups: net.sources Subject: A nifty little script to help with news... Message-ID: <959@trwatf.UUCP> Date: Mon, 3-Jun-85 13:08:36 EDT Article-I.D.: trwatf.959 Posted: Mon Jun 3 13:08:36 1985 Date-Received: Tue, 4-Jun-85 07:55:51 EDT Reply-To: root@trwatf.UUCP (Lord Frith) Organization: TRW Advanced Technology Facility, Merrifield VA. Lines: 123 Here's a shell script that makes restoring news articles from the junk directory a little less painful... =================================================================== #! /bin/sh # @(#)mvjunk.sh (TRW Advanced Technology Facility) STA 2-Jun-1985 # # Move news files out of junk and into their proper directories, # updating the active list and localgroups as we go. Unknown newsgroups # are created and the article installed. # # Be CAREFULL with that active list! Although we try to write out # buffers as quickly as possible, conflicts can occur if someone else # tries to use it at the same time this script is running! # # Strange occurences are dribbled into mvjunk-log. # # TRW DSG EDS SISD SDL ATF STA JUNK=/h/news/junk NEWSDIR=/h/news LIB=/usr/lib/news : See line 88 chmod u+wr $LIB/active cd $JUNK if /bin/test -z "`ls`" ; then exit fi chmod u+wr * for j in $JUNK/* do for group in `egrep '^Newsgroups:' $j | head -1 | \ sed 's;Newsgroups:[ ];;' | \ sed 's;,; ;g'` do l=`egrep '^Control:' $j` if /bin/test -n "$l" ; then GROUPDIR="control" group="control" else GROUPDIR=`echo $group | sed 's;\.;\/;g'` fi # Sick Lex... really sick! cd $NEWSDIR if /bin/test -d $GROUPDIR ; then cd $GROUPDIR l=`ls` if /bin/test -n "$l" ; then a=`ls | sort -r -n` for f in $a do if /bin/test -f "$f" ; then article=`echo $f "+1" | bc` break fi done else article=1 fi else mkdir $NEWSDIR/$GROUPDIR article=1 fi cd $NEWSDIR/$GROUPDIR if /bin/test ! -d "$article" ; then cp $j $NEWSDIR/$GROUPDIR/$article chmod ugo+wrx $NEWSDIR/$GROUPDIR/$article chown uucp $NEWSDIR/$GROUPDIR/$article chgrp daemon $NEWSDIR/$GROUPDIR/$article entry=`egrep "^$group " $LIB/active` if /bin/test -z "$entry" ; then echo $group " This is $group." | \ awk '{ print "/usr/lib/news/inews -C " $1 " << E_O_F" ; \ for ( i = 2 ; i <= NF ; i++ ) printf "%s ",$i ; \ printf "\n" ; print "E_O_F" }' | sh -x the_date=`date` echo "Created group $group at $date" >> $LIB/mvjunk-log entry="$group 00001 00001 y" >> $LIB/localgroups fi entry="^$entry " the_date=`date` # # There should be a way of passing shell variables into awk, but since # we don't know how to do that we just hardwire it. Kludgy... no? # echo $article $entry $the_date | \ awk 'BEGIN { FS = " " } \ { if ( NF != 11 ) printf "Munged active entry: %s\n",$0 >"/usr/lib/news/mvjunk-log" ; \ if ( length($1) > 5 ) printf "Field too large: %s\n",$0 >"/usr/lib/news/mvjunk-log" ; \ if ( length($3) > 5 ) printf "Field too large: %s\n",$0 >"/usr/lib/news/mvjunk-log" ; \ if ( length($4) > 5 ) printf "Field too large: %s\n",$0 >"/usr/lib/news/mvjunk-log" ; \ printf "/%s/s;%s;",$2,$3 ; \ for ( i = 5 - length($1) ; i > 0 ; i-- ) printf "0" ; \ print $1 ";" ; \ if ( length($4) < 5 ) { \ printf "s;%s;",$4 ; \ for ( i = 5 - length($1) ; i > 0 ; i-- ) printf "0" ; \ print $4 ";" \ } \ if ( $5 != "y" && $5 != "n" ) print "s;.$;y;" } \ END { printf "w\nq\n" }' | ed - $LIB/active else echo "Hey, there's a directory called $NEWSDIR/$GROUPDIR/$article!" echo "Hey, there's a directory called $NEWSDIR/$GROUPDIR/$article!" >> $LIB/mvjunk-log fi done if /bin/test -f $NEWSDIR/$GROUPDIR/$article ; then /bin/rm -f $j # But my MOTHER lives in Hackensack! else echo "Couldn't find the article I just installed!" echo "Couldn't find the article I just installed!" >> $LIB/mvjunk-log fi done -- UUCP: ...{decvax,ihnp4,allegra}!seismo!trwatf!root - Lord Frith ARPA: trwatf!root@SEISMO "Money from da Buddah"