Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!mailrus!cwjcc!hal!ncoast!nc386!allbery From: allbery@nc386.UUCP (Brandon S. Allbery) Newsgroups: news.software.b Subject: Re: bdf for use in C news (was Re: C news vs B news speed) Message-ID: <1989Jul23.182920.15519@nc386.uucp> Date: 23 Jul 89 18:29:20 GMT References: <1989Jul12.210254.8631@utzoo.uucp> <1018@cniysc.cinnet.COM> <297@ecijmm.UUCP> <411@lxn.eds.com> Sender: allbery@nc386.uucp (Brandon S. Allbery) Reply-To: allbery@nc386.UUCP (Brandon S. Allbery) Organization: North Coast Computer Resources, Cleveland, OH Lines: 33 In-reply-to: chris@lxn.eds.com (Christopher D. Orr) There is a very simple way to extract the number of free blocks from a System V "df"; it's currently working on nc386 (SCO Xenix), telotech (Altos System V) and ncoast (AT&T System III(!)), each of which has a slightly different "df" output (in fact, I had to rewrite "bdf"-for-Perl to work on ncoast). Extracted from our "spacefor": ## this is set up for the stupid System V df # which only proves that Collyer and Spencer don't understand System V df.... df $arg | sed 's/^[^ ]* *([^)][^)]*): *\([0-9][0-9]*\) .*$/\1/' | awk "{ nb = (\$1 - $desire) * $dfunit / $1 if (nb > 10000) nb = 10000 # ensure representable as integer nb = int(nb) if (nb <= 0) print 0 else print nb exit }" Note the "sed" command in the pipeline; it extracts the "blocks" part of the "df" output, and does so quite portably. I left the "awk" mostly as is, but could have written the sed script as part of the awk script instead or performed other optimizations. ++Brandon -- Brandon S. Allbery, moderator of comp.sources.misc allbery@NCoast.ORG uunet!hal.cwru.edu!ncoast!allbery ncoast!allbery@hal.cwru.edu * This message brought to you courtesy the "Watcher" for the 4th NCoast *