Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!uunet!rbj From: rbj@uunet.UU.NET (Root Boy Jim) Newsgroups: comp.unix.admin Subject: Re: Overflowing wtmp Keywords: solution, C, mail me for a copy Message-ID: <120636@uunet.UU.NET> Date: 30 Jan 91 20:25:26 GMT References: <338@alchemy.UUCP> <120587@uunet.UU.NET> <1991Jan30.124501.6670@mp.cs.niu.edu> Organization: UUNET Communications Services, Falls Church, VA Lines: 56 In article <1991Jan30.124501.6670@mp.cs.niu.edu> rickert@mp.cs.niu.edu (Neil Rickert) writes: >In article <120587@uunet.UU.NET> rbj@uunet.UU.NET (Root Boy Jim) writes: >>In article <338@alchemy.UUCP> bbs@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 Close the gap of the dark year in between