[comp.sources.d] A perl program to change usg style dfs into Berkeley

craig@ncrcpx.UUCP (R. Craig Peterson) (02/06/88)

Well, I've been dabbling with the new perl language that was posted
recently, and put together a cute little program that shows berkeley
style dfs...  There was some c source posted not too long ago to do
the same, but there were some problems running it on my system, and
since perl was there, I used it instead of fixing the c version.

The input (which it gets itself from df -t) looks like:

/usr/acct       (/dev/dsk/1s1):    34928 blocks   13049 i-nodes
                   total:   233070 blocks   29120 i-nodes
/               (/dev/dsk/0s1):    28878 blocks    9506 i-nodes
                   total:   212924 blocks   26608 i-nodes

The output looks like:

Filesystem     kbytes    used  avail capacity  iused   ifree %iused Mounted on
/usr/acct      116535   99073  17462    85%    16071   13049    55% 1s1
/              106462   92023  14439    86%    17103    9505    64% 0s1

At least for my system.  You might want to change the substitution
near the last line of the program if you do/don't want the name of
the device the disk is mounted on to be truncated.  Have fun.

(P.S.  Great work with Perl, Larry!!  It looks like I'll be using it 
alot more in the future!  For the rest of you, if you haven't looked at
Perl, and you process alot of strings, etc., you're missing alot!)

#--------------------------------CUT HERE-------------------------------------
#! /bin/sh
#
# This is a shell archive.  Save this into a file, edit it
# and delete all lines above this comment.  Then give this
# file to sh by executing the command "sh file".  The files
# will be extracted into the current directory owned by
# you with default permissions.
#
# The files contained herein are:
#
# -rwxrwxr-x  1 craig         867 Feb  5 11:40 bdf
#
echo 'x - bdf'
if test -f bdf; then echo 'shar: not overwriting bdf'; else
sed 's/^X//' << '________This_Is_The_END________' > bdf
X#!/bin/perl
X# A cute berkeley style df formatter for those running USG df
X# Do what you want with it; it's yours.
X# R. Craig Peterson, N8INO
Xopen(Df, 'df -t|') || die "Can't run df.";
X
Xformat top =
XFilesystem     kbytes    used  avail capacity  iused   ifree %iused Mounted on
X.
Xformat stdout =
X@<<<<<<<<<<<< @>>>>>> @>>>>>> @>>>>>    @>%   @>>>>>  @>>>>>    @>% @<<<<<<<<<<<<<<<<
X$fs           $kbytes $used   $avail  $capacity $iused $inodes $piused $name
X.
X
Xwhile (<Df>)
X{
X	if (/total/) {
X		($d,$tblocks,$d,$tinodes,$d) = split(' ');
X		$kbytes = $tblocks * 512 / 1024;
X		$used = ($tblocks - $blocks) * 512 / 1024;
X		$avail = $blocks * 512 / 1024;
X		$capacity = 100 - ($blocks / $tblocks * 100);
X		$iused = $tinodes - $inodes;
X		$piused = $iused / $tinodes * 100;
X		write;
X	} else {
X		($fs,$name,$blocks,$d,$inodes,$d) = split;
X		$name =~ s![(): \t]|/dev/dsk/!!g;
X	}
X}
________This_Is_The_END________
if test `wc -l < bdf` -ne 30 ; then
	echo 'shar: bdf was damaged during transit (should have been 30  bytes)'
fi
fi		; : end of overwriting check
exit 0
-- 
R. Craig Peterson		"Next time someone asks you if you're a god
ncrlnk!ncrcam!ncrcpx!craig	 say YES!!"
N8INO					Ghost Busters
E Pluribus Unum 	(NSA stuff - terrorist, DES, cipher, secret, NRO, CIA)

paul@vixie.UUCP (Paul Vixie Esq) (02/08/88)

In article <1821621@ncrcpx.UUCP> craig@ncrcpx.UUCP (R. Craig Peterson) writes:
#[...] berkeley style dfs...  There was some c source posted not too long ago
#to do the same, but there were some problems running it on my system, and
#since perl was there, I used it instead of fixing the c version.

There is a new, fixed-up version of bdf.c in testing.  I'll be sending it out
to comp.sources.somethingorother pretty soon now...

#The input (which it gets itself from df -t) looks like:
#
#/usr/acct       (/dev/dsk/1s1):    34928 blocks   13049 i-nodes
#                   total:   233070 blocks   29120 i-nodes
#/               (/dev/dsk/0s1):    28878 blocks    9506 i-nodes
#                   total:   212924 blocks   26608 i-nodes

Beware that there can be blanks and asterisks in irritating places in the
output of 'df -t' on a USG system.  Also, the /dev/dsk can be /dev/dsk/abcdef
(six letters) on some systems.  Nice to have all this stuff standardized...

#The output looks like:
#
#Filesystem     kbytes    used  avail capacity  iused   ifree %iused Mounted on
#/usr/acct      116535   99073  17462    85%    16071   13049    55% 1s1
#/              106462   92023  14439    86%    17103    9505    64% 0s1

This is backwards from Berkeley DF -- the "Filesystem" column has the device
file and the "Mounted on" has the mount point.

#(P.S.  Great work with Perl, Larry!!  It looks like I'll be using it 
#alot more in the future!  For the rest of you, if you haven't looked at
#Perl, and you process alot of strings, etc., you're missing alot!)

I think if I'd had perl when I wrote bdf.c, I'd still have made up my own.
Nice as it is, the number of patches per week make perl a little hard to keep
up with, especially for the 10-odd USG systems I administer.

Still, Perl is obviously a better choice than C for this kind of task; the
fact that your version fits in 30 very readable lines vs. my C version at
around 200 messy ones clearly shows the advantages of Perl.

I therefore echo your sentiments -- great job, Larry.

#if test `wc -l < bdf` -ne 30 ; then
#	echo 'shar: bdf was damaged during transit (should have been 30  bytes)'
#fi

Actually, it "should have been 30 *LINES*", not "*BYTES*".
-- 
Paul A Vixie Esq
paul%vixie@uunet.uu.net
{uunet,ptsfa,hoptoad}!vixie!paul
San Francisco, (415) 647-7023