🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.readers
2 messages
2 total messages Started by Anon Sun, 26 Jul 1992 08:53
Wanted: /bin/sh script for mantaining KILL files.
#1927
Author: Anon
Date: Sun, 26 Jul 1992 08:53
35 lines
1816 bytes
I would like to get my hands on a script to do
some or all of the following.
 
1> Look for all kill files over X-bytes in length
1a> trim the file down until it's under X-bytes, by removing
    the first line(s) of kill commands (leaving the
    THRU line intact.
2> Remove KILL files that are older than X-days since 
    last access.
3> Mail a report to the user on which files were cleaned
    up, and what was taken out, or which files were
    deleted.
4> Can be used either system-wide using cron, or
    on an individual basis, like in .profile
 
Ok, folks... that's what I would like. I would do
it myself, but I'm still not fluent in /bin/sh scripts
to get it to work. (Plus, looking at the script or
source if U care to make it compilable would be very
useful to show me how to incorporate routines into
other code as well.)
 
I am using SCO-Xenix SysV-386.
 
(ps: still working on getting my From: field fixed. :) )
 


--
       _ _ _                  __
      ' ) ) )                /  )     _/_
       / / / o _. __  _ --- /  / __.  /  __.
      / ' (_<_(__/ (_(_)   /__/_(_/|_<__(_/|_
          C  O  N  S  U  L  T  A  N  T  S
       Kenn Booth II >-< kennii@wybbs.mi.org
Re: Wanted: /bin/sh script for mantaining KILL files.
#1934
Author: Tom Christiansen
Date: Mon, 27 Jul 1992 15:43
104 lines
4237 bytes
Archive-name: killkill
Submitter: Tom Christiansen <tchrist@convex.com>

From the keyboard of an unknown person @wybbs.mi.org:
:I would like to get my hands on a script to do
:some or all of the following.
: 
:1> Look for all kill files over X-bytes in length
:1a> trim the file down until it's under X-bytes, by removing
:    the first line(s) of kill commands (leaving the
:    THRU line intact.
:2> Remove KILL files that are older than X-days since 
:    last access.
:3> Mail a report to the user on which files were cleaned
:    up, and what was taken out, or which files were
:    deleted.
:4> Can be used either system-wide using cron, or
:    on an individual basis, like in .profile
: 
:Ok, folks... that's what I would like. I would do
:it myself, but I'm still not fluent in /bin/sh scripts
:to get it to work. (Plus, looking at the script or
:source if U care to make it compilable would be very
:useful to show me how to incorporate routines into
:other code as well.)
: 
:I am using SCO-Xenix SysV-386.

Here's a Perl solution.  I'll leave the running from cron
or sending mail as an exercise for the reader.

--tom

#!/usr/bin/perl
#
# killkill -- maintain killfiles by size and age
# tchrist@convex.com    Mon Jul 27 10:35:44 CDT 1992
#
# arguments are considered user names, defaulting
# to the current user if not given.
#
# for all killfiles in a user's newsdirectory that are older than
# $MAXDAYS, unlink them, or if bigger than $MAXSIZE, save the THRU line
# and discard lines (oldest first) until size is under $MAXSIZE.  
#
# a killfile is defined by the pattern $KILLPAT; a newsdir is a
# directory residing in ~$user/$NEWSDIR.
#
# print out each killfile found, and what if anything is done to it.
# if $DEBUG is true, don't really touch any files.

require 'find.pl';

$MAXSIZE = 250;
$MAXDAYS = 30;
$KILLPAT = '^KILL$';
$NEWSDIR = 'News';
$DEBUG = 0;

if (@ARGV == 0) { # no args means default to current user
    @ARGV = (       $ENV{USER}
		 || $ENV{LOGNAME}
		 || (getpwuid($>))[0]
		 || die "Cannot determine user for id $>"
	    );
} 

print "$0: maxsize is $MAXSIZE, maxdays is $MAXDAYS, debug is $DEBUG\n";

while ($user = shift) {
    $home = (getpwnam($user))[7];
    $newsdir = "$home/$NEWSDIR";
    next unless -d $newsdir;
    &find($newsdir);
} 

sub wanted {
    /$KILLPAT/o || return;
    $size = -s $_;
    $age  = -M _;  
    printf "%-50s  age = %5.1f   size = %d\n", $name, $age, $size;
    if ($age > $MAXDAYS) {
	print "\tunlinking $name\n";
	unlink unless $DEBUG;
    } elsif ($size > $MAXSIZE) {
	print "\ttrimming $name\n";
	unless ($DEBUG) {
	    ($thru, @lines) = `cat $name`;
	    shift @lines until length("$thru @lines") < $MAXSIZE;
	    open (KF, ">$name") || die "can't write $name: $!";
	    print KF $thru, @lines;
	    close KF || die "can't close $name: $!"
	}
    } 
} 
__END__


-- 
    Tom Christiansen      tchrist@convex.com      convex!tchrist


    /earth is 98% full ... please delete anyone you can.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads