Overflowing wtmp

Root Boy Jim rbj at uunet.UU.NET
Thu Jan 31 07:25:26 AEST 1991


In article <1991Jan30.124501.6670 at mp.cs.niu.edu> rickert at mp.cs.niu.edu (Neil Rickert) writes:
>In article <120587 at uunet.UU.NET> rbj at uunet.UU.NET (Root Boy Jim) writes:
>>In article <338 at alchemy.UUCP> bbs at alchemy.UUCP (BBS Administration) writes:
>>>a copy of my "wsize" program...
>>>... I run it as a "root" crontask on the 1st and 15th
>>
>>Tsk tsk, overkill. Howabout a range of 2000 to 3000 records? Try
>>
>>		#! /bin/sh
>>		cd /usr/adm
>>		split wtmp
>>		set x?? /dev/null /dev/null /dev/null /dev/null
>>		shift `expr $# - 3`
>>		cat $* > xxx
>>		mv xxx wtmp
>>		rm -f x??
>
> Hey.  That's neat.  But what do we do if we have a 'split' that wants to
>break the file based on lines, and a 'wtmp' that doesn't contain lines?

Harumph! Don't confuse the issue with facts :-) Mea culpa.
Thank gods this wasn't unix-wizards, I'd never hear the end of it.

You can use dd, believe it or not. Call the thing below "ctail"
and invoke it as: ctail /usr/adm/wtmp 1000 36
36 is sizeof utmp

		#! /bin/sh
		#usage: ctail file count bs 
		#       count defaults to 100 
		#       bs defaults to 1 
		# 
		file=${1?"usage: $0 file [count=100] [bs=1]"}
		bs=${3-1}
		count=${2-100}
		chars=`wc -c < $file`
		recs=`expr $chars / $bs`
		skip=`expr $recs - $count`
		set $bs $count $skip
		dd < $file > $file.$$ bs=$1 count=$2 skip=$3
		mv $file.$$ $file

Throw in a couple of for loops and you've got a completely
general binary splitter.

OK, there is a moral to all this (besides being snooty :-).
UNIX provides a rich set of tools. The shell is amazing.
Only use C as a last resort. Tail -c is supposed to do what
you want, but many versions have a limit when working
relative to the front. Of course you can calculate where to start
and use it in place of dd. My version is also susceptible to
corrupted format. It should really compute backwards from the end.
-- 

	Root Boy Jim Cottrell <rbj at uunet.uu.net>
	Close the gap of the dark year in between



More information about the Comp.unix.admin mailing list