From: brendan@cs.widener.edu (Brendan Kehoe)
Newsgroups: news.admin,alt.sources,comp.lang.perl
Subject: Utility for removing spool dirs of deleted newsgroups
Followup-To: news.admin
Date: 21 Jul 1992 09:45:51 -0400
Organization: Widener University Computer Science Dept, Chester PA
Distribution: world
NNTP-Posting-Host: betty.cs.widener.edu

Archive-name: newsdir-sweep
Submitted-By: brendan@cs.widener.edu (Brendan Kehoe)

bdb@becker.GTS.ORG wrote:
>|C-News creates directories as it needs them, right?  I always run a job
>|about once a month that removes any empty directories (actually, it does
>|a depth-first find, and does an rmdir on every directory, and ignores
>|errors).  I figure it can't hurt anything, right?
>
>	why bother?

Cuz after about two years of not bothering, you've got one really
messy filesystem.  If your active file gets wiped out for any reason,
odds are the tool you'll use to recreate it will end up with a load of
newsgroups that had been rmgroup'd or otherwise deleted.  Since it's a
trivial task to keep it clean, why not do so?

This is what I use; suggestions on how to better write it (at least go_up)
are welcome.

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  newsdir-sweep chkdirs
# Wrapped by brendan@betty on Tue Jul 21 09:44:32 1992
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'newsdir-sweep' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'newsdir-sweep'\"
else
echo shar: Extracting \"'newsdir-sweep'\" \(336 characters\)
sed "s/^X//" >'newsdir-sweep' <<'END_OF_FILE'
X#!/bin/sh
X# Run from cron by the news user once each month.
XDIRS="alt bionet bitnet comp control ddn general gnu hiv ieee \
X      info k12 misc na ne news nj ny nyc opinions pa pgh phl rec sci soc \
X      su swnet talk trial u3b us vmsnet widener"
Xcd $HOME
Xfind $DIRS -type d -a -links 2 -print | /usr/lib/newsbin/chkdirs | xargs rm -f
END_OF_FILE
if test 336 -ne `wc -c <'newsdir-sweep'`; then
    echo shar: \"'newsdir-sweep'\" unpacked with wrong size!
fi
# end of 'newsdir-sweep'
fi
if test -f 'chkdirs' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'chkdirs'\"
else
echo shar: Extracting \"'chkdirs'\" \(876 characters\)
sed "s/^X//" >'chkdirs' <<'END_OF_FILE'
X#!/bin/perl
X# Check for rogue directories.
X$dir = "/var/spool/news";
X$active = "/usr/lib/news/active";
X
X%act = (); &get_active;
X
X# If a group foo.bar.d was removed, but its directory is still there,
X# remove as much as we can of /foo/bar/d (i.e., a selective rm -rf).  It
X# won't delete /foo/bar if, say, the group foo.bar.talk exists and you're
X# cleaning out /foo/bar/d.
Xwhile (<>) {
X   chop; $dir = $_; s/\//./g;
X   &go_up ($dir) unless $active{$_};
X}
X
Xsub get_active {
X  # Set hi also, since we can use that to check for groups without
X  # dirs in other utilities.
X  open (ACT, $active) || die "Can't open the active file: $!\n";
X  while (<ACT>) { @tmp = split; $active{@tmp[0]} = 1; $hi{@tmp[0]} = @tmp[1]; }
X  close ACT;
X};
X
Xsub go_up {
X  local (@dirs) = split (/\//, @_[0]);
X  local ($i);
X  for ($i = $#dirs; $i != 0; $i--) { print join ('/', @dirs[0..$i]), "\n"; }
X};
END_OF_FILE
if test 876 -ne `wc -c <'chkdirs'`; then
    echo shar: \"'chkdirs'\" unpacked with wrong size!
fi
# end of 'chkdirs'
fi
echo shar: End of shell archive.
exit 0
-- 
Brendan Kehoe, Sun Network Manager                      brendan@cs.widener.edu
Widener University                                                 Chester, PA
                                              At Bennigan's, EVERYONE gets it!
Xref: sparky news.admin:6079 alt.sex.bondage:14359 alt.censorship:6185 alt.comp.acad-freedom.talk:2371