🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nn
Article #3420

Available news in the message of the day.

#3420
From: Jeroen C. Kessels
Date: Tue, 24 Nov 1992 11:47
460 lines
14342 bytes
At our site we have automatic expiration of News articles, depending on
diskuse. If the disk usage passes a certain threshold, then articles
will be expired until enough diskspace is available. It works great, we
never lose news because of a full disk, and the diskspace is optimally
used.

The disadvantage though is that we cannot guarantee a retention period
("news is stored at least .. days"). To overcome this, I have written
the following small utility. Users can now "see" how old the available
news is, when they start NN.

The utility creates a "motd" file for NN (yes, NN has it's own message
of the day, see the NN manual).  It looks something like this:


	News available (Tue Nov 24 11:32:56 WET 1992):

	DD/MM/YY   Files  Kbytes
	-------- ------- -------
	17/11/92    3910    9796
	18/11/92   23238   64041
	19/11/92   17459   46560
	20/11/92   21677   59239
	21/11/92   19576   50846
	22/11/92    9974   29739
	23/11/92   13294   34713
	24/11/92    4118    8335
                 ------- -------
	Total:    113246  303273



#!/bin/sh
# This is a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 11/24/1992 10:08 UTC by jeroenk@cnplss7
# Source directory /usr/jeroenk/t2
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#    223 -rw------- Makefile
#   1138 -rw------- README
#   1569 -rw------- dut.1
#   5597 -rwx------ dut.c
#    737 -rwx------ makemotd
#
# ============= Makefile ==============
if test -f 'Makefile' -a X"$1" != X"-c"; then
	echo 'x - skipping Makefile (File already exists)'
else
echo 'x - extracting Makefile (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
CFLAGS=		-O
INSTALLPATH=	/usr/local/bin
MANPATH=	/usr/man/man1
X
all:	dut
X
dut:	dut.o Makefile
X	$(CC) $(CFLAGS) dut.o -o dut
X
install:
X	cp dut $(INSTALLPATH)
X	cp dut.1 $(MANPATH)
X
clean:
X	rm -f *.o dut a.out core VILASTFILE
SHAR_EOF
chmod 0600 Makefile ||
echo 'restore of Makefile failed'
Wc_c="`wc -c < 'Makefile'`"
test 223 -eq "$Wc_c" ||
	echo 'Makefile: original size 223, current size' "$Wc_c"
fi
# ============= README ==============
if test -f 'README' -a X"$1" != X"-c"; then
	echo 'x - skipping README (File already exists)'
else
echo 'x - extracting README (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'README' &&
dut - Report disk usage sorted by time.
X
X
DESCRIPTION
X
The dut command lists diskusage sorted by date. It was originally
developed to generate a "message of the day" with the number of news
articles available on the system. It can also be used to get some idea
about the age of the files on the system.
X
An example of some typical output:
X
X	DD/MM/YY   Files  Kbytes
X	-------- ------- -------
X	07/11/92      28     253
X	08/11/92       5       4
X	09/11/92      18     460
X	10/11/92       5       5
X	11/11/92      35     632
X	12/11/92       9      12
X	         ------- -------
X	Total:       153    3074
X
X
COMPILING
X
DUT should compile without changes on most kinds of Unix. It has been
tested on SunOS 4.1.2, Ultrix 4.2A, IRIX 4.0.1, and System V/68 R3V5.
X
Look at the "Makefile", maybe edit the INSTALLPATH and MANPATH.
Type "make" to compile the program.
Type "make install" to install the program.
X
X
FOR NN ADMINISTRATORS
X
As an example I have included a small Bourne-shell script "makemotd"
that generates a Message Of The Day for NN. You'll have to edit it to
change some paths, copy it somewhere, and add a line to the cron. Have
fun!
SHAR_EOF
chmod 0600 README ||
echo 'restore of README failed'
Wc_c="`wc -c < 'README'`"
test 1138 -eq "$Wc_c" ||
	echo 'README: original size 1138, current size' "$Wc_c"
fi
# ============= dut.1 ==============
if test -f 'dut.1' -a X"$1" != X"-c"; then
	echo 'x - skipping dut.1 (File already exists)'
else
echo 'x - extracting dut.1 (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'dut.1' &&
.TH DUT 1 "12 November 1992"
.SH NAME
dut \- Report disk usage sorted by time.
.SH SYNTAX
.B dut
[\-e path] [path]
.SH DESCRIPTION
The
.I dut
command lists diskusage sorted by date. It was originally developed
to generate a "message of the day" with the number of news
articles available on the system. It can also be used to get
some idea about the age of the files on the system.
.PP
An example of some typical output:
.IP
DD/MM/YY   Files  Kbytes
.br
-------- ------- -------
.br
05/11/92      20     709
.br
06/11/92      20     382
.br
07/11/92      28     253
.br
08/11/92       5       4
.br
09/11/92      18     460
.br
10/11/92       5       5
.br
11/11/92      35     632
.br
12/11/92       9      12
.br
X         ------- -------
.br
Total:       153    3074
.SH OPTIONS
.TP 10
.B \-e path
Exclude all files in the "path". The path must be relative to the
path to be analysed. You may specify more paths to
be excluded with multiple "-e" specifications.
.TP 10
.B path
The path to be analysed. Default is the current working directory.
.SH EXAMPLES
.br
dut /usr/spool
.br
dut -e mail /usr/spool
.br
dut -e mail -e mqueue /usr/spool
.SH BUGS
The number of bytes reported is the exact number of bytes in all the files.
This is probably different from your "du", because "du" usually
reports the number of whole disk-blocks used.
.PP
Links are counted more than once.
.SH "SEE ALSO"
du(1)
.SH AUTHOR
Jeroen C. Kessels, Software Engineer, Philips C&P-LSS
.br
SAQ-P730, P.O. Box 218, 5600 MD Eindhoven, The Netherlands
.br
Usenet = jeroenk@cnplss7.cnps.philips.nl
SHAR_EOF
chmod 0600 dut.1 ||
echo 'restore of dut.1 failed'
Wc_c="`wc -c < 'dut.1'`"
test 1569 -eq "$Wc_c" ||
	echo 'dut.1: original size 1569, current size' "$Wc_c"
fi
# ============= dut.c ==============
if test -f 'dut.c' -a X"$1" != X"-c"; then
	echo 'x - skipping dut.c (File already exists)'
else
echo 'x - extracting dut.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'dut.c' &&
/*
dut.c	Report disk usage sorted by time.
X
usage:	dut [-e path] [path]
where:	  -e path	Path to be excluded, relative to the working directory.
X	  path		working directory. Default is the current working
X	  		directory ("pwd").
X
The dut command lists diskusage sorted by date. It was  originally
developed to generate a "message of the day" with the number of news
articles available on the system. It  can also  be used to get some idea
about the age of the files on the system.
*/
X
X
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <ftw.h>
#include <stdio.h>
X
#define USAGE	"[-e path] [path]"
X
/* Linked list containing statistics per day. */
struct DayEntry {
X  time_t FirstSecond;		/* First second of the day. */
X  time_t LastSecond;		/* Last second of the day. */
X  long	Bytes;			/* Bytes in all the files. */
X  long	Files;			/* Number of files. */
X  struct DayEntry *next;	/* Link to next item, NULL if last. */
X  };
struct DayEntry *DayTop = NULL;    /* First entry. */
struct DayEntry *DayHere = NULL;   /* Current entry. */
struct DayEntry *DayPrev = NULL;   /* Previous entry. */
X
/* Linked list containing paths to be excluded. */
struct ExcludeEntry {
X  char exclude[256];		/* Path to exclude. */
X  int length;			/* Length of path to exclude (characters). */
X  struct ExcludeEntry *next;	/* Link to next item, NULL if last. */
X  };
struct ExcludeEntry *ExcludeTop = NULL;	/* First entry. */
struct ExcludeEntry *ExcludeHere = NULL;	/* Current entry. */
X
X
X
X
int dodir(path,info,status)
/* Add the statistics of a single file. This subroutine is called by the 
X   iterative "ftw" system call, for every file. */
char	*path;			/* Name of current file. */
struct stat *info;		/* Stat info about the file. */
int	status;			/* Status from ftw. */
{
/* Exclude anything but files. */
if (status != FTW_F) return(0);		/* exit. */
X
/* Exclude directories specified with "-i" on the command line. */
ExcludeHere = ExcludeTop;
while (ExcludeHere != NULL) {
X  if (strncmp(path,ExcludeHere->exclude,ExcludeHere->length) == 0) return(0);				/* Exit. */
X  ExcludeHere = ExcludeHere->next;	/* Next. */
X  }
X
/* Walk through all the logged days, searching where the file's timestamp
X   fits. If found, then add the file to the statistics of that day. */
DayHere = DayTop;
DayPrev = NULL;
while (DayHere != NULL) {
X  /* If inside this day, then add to it's statistics and exit. */
X  if ((info->st_mtime >= DayHere->FirstSecond) &&
X      (info->st_mtime < DayHere->LastSecond)) {
X    DayHere->Bytes += info->st_size;
X    ++DayHere->Files;
X    return(0);
X    }
X  /* Next day. If the file is younger than this day, then terminate the
X     search. */
X  if (info->st_mtime >= DayHere->LastSecond)
X    { DayPrev = DayHere;
X      DayHere = DayHere->next;
X      }
X    else DayHere = NULL;
X  }
X
/* If we get here, then the file was created on a day not yet logged,
X   so create a new day entry. */
DayHere = (struct DayEntry *)malloc(sizeof(struct DayEntry));
DayHere->Bytes = info->st_size;
DayHere->Files = 1;
DayHere->FirstSecond = info->st_mtime - info->st_mtime % 86400;
DayHere->LastSecond = DayHere->FirstSecond + 86400;
if (DayPrev == NULL)		/* Add to linked list. */
X  { if (DayTop == NULL)
X      DayHere->next = NULL;
X      else DayHere->next = DayTop->next;
X    DayTop = DayHere;
X    }
X  else {
X    DayHere->next = DayPrev->next;
X    DayPrev->next = DayHere;
X    }
X
return(0);  
}
X
X
X
X
main(argc,argv)
int	argc;
char	*argv[];
{
char	WorkDir[256];		/* Base directory. */
long	Bytes = 0;		/* Running Totals. */
long	Files = 0;
struct	tm *t1;                  /* Workvariables. */
int	i;
char	s[256];
X
/* Initialise default workdirectory. */
sprintf(WorkDir,".");
X
/* Accept parameters from the command line. */
i = 1;
while (i < argc) {
X  if (strcmp(argv[i],"-e") == 0)			/* -e */
X    { if (i+1 >= argc) {
X        fprintf(stderr,"Usage: %s %s\n",argv[0],USAGE);
X        exit(1);
X        }
X      ExcludeHere = (struct ExcludeEntry *)malloc(sizeof(struct ExcludeEntry));
X      sprintf(ExcludeHere->exclude,"%s",argv[i+1]);
X      ExcludeHere->next = ExcludeTop;
X      ExcludeTop = ExcludeHere;
X      i++;
X      }
X    else if (strncmp(argv[i],"-",1) == 0)		/* bad options */
X    { fprintf(stderr,"Usage: %s %s\n",argv[0],USAGE);
X      exit(0);
X      }
X    else sprintf(WorkDir,"%s",argv[i]);			/* other */
X  i++;
X  }
X
/* Walk through all the exclude paths, and add the working directory. */
ExcludeHere = ExcludeTop;
while (ExcludeHere != NULL) {
X  sprintf(s,"%s/%s",WorkDir,ExcludeHere->exclude);
X  sprintf(ExcludeHere->exclude,s);
X  ExcludeHere->length = strlen(ExcludeHere->exclude);
X  ExcludeHere = ExcludeHere->next;
X  }
X
/* Fire up the iterative "ftw" system call. It will cause a call to the "dodir"
X   subroutine for every file. */
ftw(WorkDir,dodir,20);
X
/* Show results on standard output. */
fprintf(stdout,"DD/MM/YY   Files  Kbytes\n");
fprintf(stdout,"-------- ------- -------\n");
DayHere = DayTop;			/* For every day. */
while (DayHere != NULL) {
X  t1 = localtime(&DayHere->FirstSecond);
X  fprintf(stdout,"%02i/%02i/%02i %7d %7d\n",t1->tm_mday,t1->tm_mon+1,
X    t1->tm_year,DayHere->Files,DayHere->Bytes / 1024);
X  Files += DayHere->Files;		/* Maintain totals. */
X  Bytes += DayHere->Bytes;
X  DayPrev = DayHere;			/* Next day. */
X  DayHere = DayHere->next;
X  free(DayPrev);
X  }
fprintf(stdout,"         ------- -------\n");
fprintf(stdout,"Total:   %7d %7d\n",Files,Bytes / 1024);
X
/* Clean up the exluded paths. */
ExcludeHere = ExcludeTop;
while (ExcludeHere != NULL) {
X  ExcludeTop = ExcludeHere;
X  ExcludeHere = ExcludeHere->next;
X  free(ExcludeTop);
X  }
X
exit(0);
}
SHAR_EOF
chmod 0700 dut.c ||
echo 'restore of dut.c failed'
Wc_c="`wc -c < 'dut.c'`"
test 5597 -eq "$Wc_c" ||
	echo 'dut.c: original size 5597, current size' "$Wc_c"
fi
# ============= makemotd ==============
if test -f 'makemotd' -a X"$1" != X"-c"; then
	echo 'x - skipping makemotd (File already exists)'
else
echo 'x - extracting makemotd (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'makemotd' &&
#!/bin/sh
#
# Example script for NN administrators.
#
# Generate a Message of the day for NN, containing a "news available"
# message. Suggested startup via the cron:
#     0 0,8,12,16 * * * /usr/local/bin/makemotd
X
X
# Use a temporary file to catch the output until it is complete.
tmp="/tmp/motd.$$"
X
# Generate header lines.
echo "News available (`date`):" > $tmp
echo "" >> $tmp
X
# Generate disk statistics. Exclude two c-news directories.
/usr/local/bin/dut -e in.coming -e out.going /usr/spool/news >> $tmp
X
# Generate trailer lines.
echo "" >> $tmp
echo "Happy newsreading!" >> $tmp
X
# Copy to the Message Of The Day file.
cp $tmp /usr/local/lib/nn/motd
chmod 644 $ff				# Readable for everybody.
X
# Clean up temp file.
rm -f $tmp
SHAR_EOF
chmod 0700 makemotd ||
echo 'restore of makemotd failed'
Wc_c="`wc -c < 'makemotd'`"
test 737 -eq "$Wc_c" ||
	echo 'makemotd: original size 737, current size' "$Wc_c"
fi
exit 0
-- 
Jeroen C. Kessels, Software Engineer, Philips C&P-LSS
tel. (+31 40 7)33096
SAQ-P730, P.O. Box 218, 5600 MD Eindhoven, The Netherlands
Usenet = jeroenk@cnplss7.cnps.philips.nl
Technical Details
Message-ID: <1992Nov24.114746.26681@cnplss5.cnps.philips.nl>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!archive!mbox2nntp-news.software.nn.mbox.zip!sparky!uunet!mcsun!sun4nl!relay.philips.nl!cnplss5!cnplss7!jeroenk

Show Full Headers
Complete Article Headers
Message-ID: <1992Nov24.114746.26681@cnplss5.cnps.philips.nl>
Subject: Available news in the message of the day.
Date: Tue, 24 Nov 1992 11:47:46 GMT
From: jeroenk@cnplss7.cft.philips.nl (Jeroen C. Kessels)
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!archive!mbox2nntp-news.software.nn.mbox.zip!sparky!uunet!mcsun!sun4nl!relay.philips.nl!cnplss5!cnplss7!jeroenk
Newsgroups: news.software.nn
Sender: news@cnplss5.cnps.philips.nl (USENET News System)
Nntp-Posting-Host: cnplss7
Organization: Philips Communications & Processing Services, Eindhoven
Lines: 460