From: robm@test-kiosk.eecs.berkeley.edu (Rob McNicholas)
Subject: trimming wtmp (was: /usr filesystem overloaded)
Date: 1996/08/23 [thread overview]
Message-ID: <ww4pw4h7j2n.fsf_-_@test-kiosk.eecs.berkeley.edu> (raw)
In-Reply-To: j_erlank.17.000847D6@sames.co.za
Someone asked if there was a better way to maintain the wtmp file
instead of just truncating it. Attached is a script i wrote many
years ago which prunes records from the top of the file, leaving the
most recent records; i have been using it on our Ultrix 4.2 systems
ever since. Don't know what will happen under DU. Use at your own
risk.
-rob
#!/bin/csh -f
# usage: trimwtmp [numrec]
# script to trim wtmp
# Rob McNicholas, 1/30/91
# version of 3/18/92
#
# Deletes the first _numrec_ entries from the /usr/adm/wtmp file.
# If _numrec_ is not specified, 1000 is the default.
#
# Suggested use is as a crontab entry, e.g.
# 42 4 15,30 * * sh /usr/etc/trimwtmp 2>&1 | Mail -s "wtmp trim" root
#
# Bugs:
# Doesn't check to be sure argument is an integer
#
# the default number of records to trim
set numrec_default = 1000
# size of one wtmp record
set recsize = 36
# file to act on
set wtmpfile = /usr/adm/wtmp
# current size of file
set filesize = `wc -c $wtmpfile`
# trim off file name from wc's output
set filesize = $filesize[1]
# number of records to delete
if ( $#argv == 0 ) then
# user didn't specify how many records, so use default
set numrec_del = $numrec_default
else if ($#argv == 1) then
# use number from command line (and hope it's a number!)
set numrec_del = $1
else
echo "Usage: $0 [numrec]"
exit (1)
endif
echo "Trimming $numrec_del records"
# current number of records in the file
@ cur_rec = `expr $filesize / $recsize`
# number of records to keep is cur_rec - numrec_del
@ keep = `expr $cur_rec - $numrec_del`
if ($keep < 0) then
echo -n "Tried to delete more records ($numrec_del) than actually "
echo "exist ($cur_rec)"
exit (1)
else
# put what we are deleting in a 'old' file
dd if=$wtmpfile of=/usr/adm/wtmp.old bs=$recsize count=$numrec_del
# put what we want to keep in a temporary file
dd if=$wtmpfile of=/usr/adm/wtmp.$$ bs=$recsize skip=$numrec_del
# trash the original file and replace with our shortened version
mv -f /usr/adm/wtmp.$$ $wtmpfile
# compress the 'old' data (-f forces overwrite if file already exists)
compress -f /usr/adm/wtmp.old
# say what happened
echo "Successfully trimmed $numrec_del records from $wtmpfile"
echo "Old records are in /usr/adm/wtmp.old.Z"
exit(0)
endif
# EOF: trimwtmp
prev parent reply other threads:[~1996-08-23 4:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-08-21 4:00 /usr filesystem overloaded Johan Erlank
1996-08-21 4:00 ` Marek Pola/1995
1996-08-22 4:00 ` Hendrik Roepcke
1996-08-23 4:00 ` Rob McNicholas [this message]
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