.key dummy
.bra [
.ket ]
;/* uucp:c/newsdaily, (c) Wed, 12 May 1993 03:59:30 +0200 by "Kai 'wusel' Siering" <wusel@hactar.hanse.de> */

set [$$]USERNAME `findconfig USERNAME`
set [$$]NODENAME `findconfig NODENAME DOMAINNAME`
set [$$]NEWSMASTER `findconfig NEWSMASTER`
set [$$]HOSTNAME $HOSTNAME

if $[$$]NEWSMASTER eq NEWSMASTER
   set [$$]NEWSMASTER $[$$]USERNAME
endif

if $[$$]HOSTNAME eq *$HOSTNAME
   set [$$]HOSTNAME `findconfig NODENAME`
endif

set [$$]DATE `rx "say date('n', date('i')-1)"`

; since gsort tends to fail with `gsort: virtual memory exhausted' on low
; memory situations with an exit code of 2 (yet another UNIX port ...),
; try to run gsort before actually doing anything else. Send mail to
; newsmaster in case of failure.

set [$$]pwd `cd`
cd sys:tmp  ; for the sake of gsort which uses `/tmp/filename' =:-<
gsort <uulib:news/log >nil:
if $RC not eq 0 val
   echo  >t:newsdaily[$$].newsdaily.mail "From: newsdaily@$[$$]NODENAME ($[$$]HOSTNAME's USENET Daemon)"
   echo >>t:newsdaily[$$].newsdaily.mail "To: $[$$]NEWSMASTER"
   echo >>t:newsdaily[$$].newsdaily.mail "Subject: Unable to compute daily USENET status report ($[$$]DATE) for $[$$]HOSTNAME*N"
   echo >>t:newsdaily[$$].newsdaily.mail "Possible Reason: `gsort' ran out of memory.*N"
   avail >>t:newsdaily[$$].newsdaily.mail
   skip goodbye
endif

if not exists uulib:news/log
   echo  >t:newsdaily[$$].newsdaily.mail "From: newsdaily@$[$$]NODENAME ($[$$]HOSTNAME's USENET Daemon)"
   echo >>t:newsdaily[$$].newsdaily.mail "To: $[$$]NEWSMASTER"
   echo >>t:newsdaily[$$].newsdaily.mail "Subject: Daily USENET status report ($[$$]DATE) for $[$$]HOSTNAME*N"
   echo >>t:newsdaily[$$].newsdaily.mail "There are no recordings of any news that may have arrived. This may be due*Nto some problems, you'd better check the system ...*N"
   list uunews:in.coming >>t:newsdaily[$$].newsdaily.mail
   skip goodbye
endif

failat 21
delete uulib:news/log.ooo >nil:
rename uulib:news/log.oo     uulib:news/log.ooo >nil:
rename uulib:news/log.o      uulib:news/log.oo  >nil:
delete uulib:news/errlog.ooo >nil:
rename uulib:news/errlog.oo  uulib:news/errlog.ooo >nil:
rename uulib:news/errlog.o   uulib:news/errlog.oo  >nil:
delete uulib:news/expire.log.ooo >nil:
rename uulib:news/expire.log.oo  uulib:news/expire.log.ooo >nil:
rename uulib:news/expire.log.o   uulib:news/expire.log.oo  >nil:
rename uulib:news/expire.log     uulib:news/expire.log.o   >nil:
delete uulib:news/batchlog.ooo >nil:
rename uulib:news/batchlog.oo  uulib:news/batchlog.ooo     >nil:
rename uulib:news/batchlog.o   uulib:news/batchlog.oo      >nil:
rename uulib:news/batchlog     uulib:news/batchlog.o       >nil:
failat 10

rename uulib:news/log        uulib:news/log.o
if not exists uulib:news/errlog
   echo "" >>uulib:news/errlog noline
else
   rename uulib:news/errlog     uulib:news/errlog.o
endif

; junked groups (names)
grep 'junked ' uulib:news/log.o >t:newsdaily[$$].junked
echo "{*N   printf(*"%s\n*", *$11);*N}" >t:newsdaily[$$].junked.awk
echo "s/`//g*Ns/'//g*Ns/,/*N/g" >t:newsdaily[$$].junked.sed
gawk -f t:newsdaily[$$].junked.awk <t:newsdaily[$$].junked >t:newsdaily[$$].junked2
sed -f t:newsdaily[$$].junked.sed <t:newsdaily[$$].junked2 >t:newsdaily[$$].junked3
gsort <t:newsdaily[$$].junked3 >t:newsdaily[$$].junked4
uniq -c <t:newsdaily[$$].junked4 >t:newsdaily[$$].junked5
gsort -nr +1 <t:newsdaily[$$].junked5 >t:newsdaily[$$].junked6

;
; If you want to create groups of several hierarchies automatically if
; articles arrive there, you might want to utilize the following:
;
;echo "{*N   if(substr($2, 0, 4)==*"zer.*" || substr($2, 0, 5)==*"fras.*" || substr($2, 0, 4)==*"bln.*" || substr($2, 0, 5)==*"saar.*" || substr($2, 0, 5)==*"hanse*")" >t:newsdaily[$$].junked.awk
;echo "      printf(*"do.newgroup %s $[$$]HOSTNAME.config \*"created by newsdaily, check status!\*"\n*", *$2);*N}" >>t:newsdaily[$$].junked.awk
;gawk -f t:newsdaily[$$].junked.awk <t:newsdaily[$$].junked6 >t:newsdaily[$$].newgroupmsgs
;execute t:newsdaily[$$].newgroupmsgs

; junked articles (number/site)
echo "{*N   printf(*"%s\n*", *$4);*N}" >t:newsdaily[$$].junked.awk
gawk -f t:newsdaily[$$].junked.awk <t:newsdaily[$$].junked >t:newsdaily[$$].junked2
gsort <t:newsdaily[$$].junked2 >t:newsdaily[$$].junked3
uniq -c <t:newsdaily[$$].junked3 >t:newsdaily[$$].junked4
gsort -nr +1 <t:newsdaily[$$].junked4 >t:newsdaily[$$].junked5

; accepted artices
grep ' + ' uulib:news/log.o >t:newsdaily[$$].received
echo "{*N   printf(*"%s\n*", *$4);*N}" >t:newsdaily[$$].received.awk
gawk -f t:newsdaily[$$].received.awk <t:newsdaily[$$].received >t:newsdaily[$$].received2
gsort <t:newsdaily[$$].received2 >t:newsdaily[$$].received3
uniq -c <t:newsdaily[$$].received3 >t:newsdaily[$$].received4
gsort -nr +1 <t:newsdaily[$$].received4 >t:newsdaily[$$].received5

; duplicate articles
grep 'duplicate' uulib:news/log.o >t:newsdaily[$$].duplicates
echo "{*N   printf(*"%s\n*", *$4);*N}" >t:newsdaily[$$].duplicates.awk
gawk -f t:newsdaily[$$].duplicates.awk <t:newsdaily[$$].duplicates >t:newsdaily[$$].duplicates2
gsort <t:newsdaily[$$].duplicates2 >t:newsdaily[$$].duplicates3
uniq -c <t:newsdaily[$$].duplicates3 >t:newsdaily[$$].duplicates4
gsort -nr +1 <t:newsdaily[$$].duplicates4 >t:newsdaily[$$].duplicates5

; short articles
grep 'short by' uulib:news/log.o >t:newsdaily[$$].shortarts
echo "{*N   printf(*"%s\n*", *$4);*N}" >t:newsdaily[$$].shortarts.awk
gawk -f t:newsdaily[$$].shortarts.awk <t:newsdaily[$$].shortarts >t:newsdaily[$$].shortarts2
gsort <t:newsdaily[$$].shortarts2 >t:newsdaily[$$].shortarts3
uniq -c <t:newsdaily[$$].shortarts3 >t:newsdaily[$$].shortarts4
gsort -nr +1 <t:newsdaily[$$].shortarts4 >t:newsdaily[$$].shortarts5

; bad dates
grep 'Date:' uulib:news/log.o >t:newsdaily[$$].baddates
echo "{*N   printf(*"%s\n*", *$4);*N}" >t:newsdaily[$$].baddates.awk
gawk -f t:newsdaily[$$].baddates.awk <t:newsdaily[$$].baddates >t:newsdaily[$$].baddates2
gsort <t:newsdaily[$$].baddates2 >t:newsdaily[$$].baddates3
uniq -c <t:newsdaily[$$].baddates3 >t:newsdaily[$$].baddates4
gsort -nr +1 <t:newsdaily[$$].baddates4 >t:newsdaily[$$].baddates5

; non conforming articles
grep ' - ' uulib:news/log.o >t:newsdaily[$$].illarts.o
egrep -vi 'duplicate|junked|Date|short by' t:newsdaily[$$].illarts.o >t:newsdaily[$$].illarts
echo "{*N   printf(*"%s\n*", *$4);*N}" >t:newsdaily[$$].illarts.awk
gawk -f t:newsdaily[$$].illarts.awk <t:newsdaily[$$].illarts >t:newsdaily[$$].illarts2
gsort <t:newsdaily[$$].illarts2 >t:newsdaily[$$].illarts3
uniq -c <t:newsdaily[$$].illarts3 >t:newsdaily[$$].illarts4
gsort -nr +1 <t:newsdaily[$$].illarts4 >t:newsdaily[$$].illarts5

; unapproved postings
grep 'unapproved' uulib:news/log.o >t:newsdaily[$$].unapproved
echo "{*N   printf(*"%s\n*", *$4);*N}" >t:newsdaily[$$].unapproved.awk
gawk -f t:newsdaily[$$].unapproved.awk <t:newsdaily[$$].unapproved >t:newsdaily[$$].unapproved2
gsort <t:newsdaily[$$].unapproved2 >t:newsdaily[$$].unapproved3
uniq -c <t:newsdaily[$$].unapproved3 >t:newsdaily[$$].unapproved4
gsort -nr +1 <t:newsdaily[$$].unapproved4 >t:newsdaily[$$].unapproved5

; join the above for a total number of problems
;
; Due to a BUG in c:join (37.1), I've to use type instead =:-<
;                     - wusel, Thu, 13 May 1993 03:17:31 +0200
;
;join t:newsdaily[$$].shortarts2 t:newsdaily[$$].baddates2 t:newsdaily[$$].illarts2 t:newsdaily[$$].unapproved2 as t:newsdaily[$$].miscproblems2
type t:newsdaily[$$].shortarts2 t:newsdaily[$$].baddates2 t:newsdaily[$$].illarts2 t:newsdaily[$$].unapproved2 >t:newsdaily[$$].miscproblems2
gsort <t:newsdaily[$$].miscproblems2 >t:newsdaily[$$].miscproblems3
uniq -c <t:newsdaily[$$].miscproblems3 >t:newsdaily[$$].miscproblems4
gsort -nr +1 <t:newsdaily[$$].miscproblems4 >t:newsdaily[$$].miscproblems5

echo  >t:newsdaily[$$].newsdaily.mail "From: newsdaily@$[$$]NODENAME ($[$$]HOSTNAME's USENET Daemon)"
echo >>t:newsdaily[$$].newsdaily.mail "To: $[$$]NEWSMASTER"
echo >>t:newsdaily[$$].newsdaily.mail "Subject: Daily USENET status report ($[$$]DATE) for $[$$]HOSTNAME"
set [$$]LINES `lines t:newsdaily[$$].junked6`
if $[$$]LINES ge 1 val
   echo >>t:newsdaily[$$].newsdaily.mail "*NUnknown newsgroups (by number of articles):*N-------------------------------------------"
   type >>t:newsdaily[$$].newsdaily.mail t:newsdaily[$$].junked6
endif
set [$$]LINES `lines t:newsdaily[$$].junked5`
if $[$$]LINES ge 1 val
   echo >>t:newsdaily[$$].newsdaily.mail "*NUnknown newsgroups (by sites sending them):*N-------------------------------------------"
   type >>t:newsdaily[$$].newsdaily.mail t:newsdaily[$$].junked5
endif
set [$$]LINES `lines t:newsdaily[$$].duplicates5`
if $[$$]LINES ge 1 val
   echo >>t:newsdaily[$$].newsdaily.mail "*NDuplicate articles (by system):*N-------------------------------"
   type >>t:newsdaily[$$].newsdaily.mail t:newsdaily[$$].duplicates5
endif
set [$$]LINES `lines t:newsdaily[$$].miscproblems5`
if $[$$]LINES ge 1 val
   echo >>t:newsdaily[$$].newsdaily.mail "*NDropped articles for misc. reasons (by system):*N-----------------------------------------------"
   type >>t:newsdaily[$$].newsdaily.mail t:newsdaily[$$].miscproblems5
   echo >>t:newsdaily[$$].newsdaily.mail "*NDropped articles (by reason):*N-----------------------------"
   type >>t:newsdaily[$$].newsdaily.mail t:newsdaily[$$].shortarts
   type >>t:newsdaily[$$].newsdaily.mail t:newsdaily[$$].baddates
   type >>t:newsdaily[$$].newsdaily.mail t:newsdaily[$$].illarts
   type >>t:newsdaily[$$].newsdaily.mail t:newsdaily[$$].unapproved
endif
set [$$]LINES `lines t:newsdaily[$$].received5`
if $[$$]LINES ge 1 val
   echo >>t:newsdaily[$$].newsdaily.mail "*NNumber of articles accepted (by system):*N----------------------------------------"
   type >>t:newsdaily[$$].newsdaily.mail t:newsdaily[$$].received5
endif
if exists uulib:news/errlog.o
   set [$$]LINES `lines uulib:news/errlog.o`
   if $[$$]LINES ge 1 val
      echo >>t:newsdaily[$$].newsdaily.mail "*NContents of errlog:*N-------------------"
      type >>t:newsdaily[$$].newsdaily.mail uulib:news/errlog.o
      echo >>t:newsdaily[$$].newsdaily.mail "-------------------"
   endif
endif
if exists uulib:news/batchlog.o
   set [$$]LINES `lines uulib:news/batchlog.o`
   if $[$$]LINES ge 1 val
      echo >>t:newsdaily[$$].newsdaily.mail "*NContents of batchlog:*N-----------------------"
      type >>t:newsdaily[$$].newsdaily.mail uulib:news/batchlog.o
      echo >>t:newsdaily[$$].newsdaily.mail "-----------------------"
   endif
endif
if exists uulib:news/expire.log.o
   set [$$]LINES `lines uulib:news/expire.log.o`
   if $[$$]LINES ge 1 val
      echo >>t:newsdaily[$$].newsdaily.mail "*NContents of expire.log:*N-----------------------"
      type >>t:newsdaily[$$].newsdaily.mail uulib:news/expire.log.o
      echo >>t:newsdaily[$$].newsdaily.mail "-----------------------"
   endif
endif
list uunews:in.coming/bad >t:newsdaily[$$].badincomingjobs dates lformat "%-30n %8l %t %d"
set [$$]LINES `lines t:newsdaily[$$].badincomingjobs`
if $[$$]LINES ge 1 val
   echo >>t:newsdaily[$$].newsdaily.mail "*NBad jobs in uunews:in.coming/bad:*N---------------------------------"
   type >>t:newsdaily[$$].newsdaily.mail t:newsdaily[$$].badincomingjobs
   echo >>t:newsdaily[$$].newsdaily.mail "--------------------------------"
endif

lab goodbye

cd $[$$]pwd
sendmail <t:newsdaily[$$].newsdaily.mail
unset [$$]LINES
unset [$$]USERNAME
unset [$$]NODENAME
unset [$$]HOSTNAME
unset [$$]NEWSMASTER
unset [$$]DATE
unset [$$]pwd
delete t:newsdaily[$$].#? quiet
