tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
From: Maarten Litmaath <litmaath () fnal ! gov>
To: tru64-unix-managers
Subject: script to trim wtmp files - revision
Date: Fri, 21 Dec 2001 02:36:40 +0000	[thread overview]
Message-ID: <102653644221790.tru64-unix-managers.marc@archive.invalid> (raw)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: multipart/mixed; boundary="--------------0F95978D89B47A856E61AF4E", Size: 2335 bytes --]

This is a multi-part message in MIME format.
--------------0F95978D89B47A856E61AF4E
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,
on 12 Apr 2001 I posted a script "trim_wtmp" to this list.
I was recently reminded that it had a few misfeatures,
which (presumably) have been fixed now.
I have attached version 2.0.
Regards,
	Maarten
--------------0F95978D89B47A856E61AF4E
Content-Type: text/plain; charset=us-ascii;
 name="trim_wtmp"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="trim_wtmp"

#!/bin/sh
# @(#)$Id: trim_wtmp 2.0 2001/12/20 litmaath@fnal.gov $
#
# trim_wtmp - keep wtmp files at reasonable lengths
#
# example crontab entry:
#
# 25 5 * * * /usr/local/adm/trim_wtmp -k 40000
#

PATH=/bin:$PATH
export PATH

usage()
{
    echo "Usage: $0 [-k entries_kept] [-f]" >&2
    exit 1
}

override=false
min_entries=2000
entries=$min_entries
dir=/var/adm

#
# the number of bytes per wtmp/wtmpx record depends on OS and release...
# check /usr/include/utmp*.h
#

case `uname`-`uname -r` in
OSF1-V5*)
    record_wtmp=392
    record_wtmpx=384
    ;;
OSF1-V4*)
    record_wtmp=156
    record_wtmpx=164
    ;;
Linux-*)
    record_wtmp=384
    record_wtmpx=384
    dir=/var/log
    ;;
*)
    #
    # e.g. Solaris, IRIX
    #
    record_wtmp=36
    record_wtmpx=372
esac

while test $# != 0
do
    case $1 in
    -f)
	override=true
	;;
    -k)
	shift
	entries=$1
	;;
    *)
	echo "$0: illegal argument: $1" >&2
	usage
    esac
    test $# != 0 && shift
done

test "x$entries" = x && usage
expr "0$entries" : '.*[^0-9]' > /dev/null && usage

if test $entries -lt $min_entries && test $override = false
then
    echo "$0: number of entries raised from $entries to $min_entries" >&2
    entries=$min_entries
fi

cd $dir
umask 002
tmp=tmp_`date +%H%M%S`_$$
mkdir $tmp

for i in wtmp wtmpx
do
    test -f $i || continue

    eval record=\$record_$i
    size=`expr $entries '*' $record`

    set x `wc -c < $i`
    shift

    test "0$1" -gt $size || continue

    #
    # portable way to copy mode and ownership...
    #

    tar cf - $i | (cd $tmp && tar xfBp -)

    skip=`expr '(' "$1" - $size ')' / $record`

    dd ibs=$record skip=$skip if=$i of=$tmp/$i 2>&1 |
	egrep -v '^[0-9]+\+[01] records (in|out)$' || mv $tmp/$i .
done

rmdir $tmp

--------------0F95978D89B47A856E61AF4E--

                 reply	other threads:[~2001-12-21  2:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox