Path: utzoo!mnetor!uunet!husc6!hao!ames!ucsd!sdcsvax!ucsdhub!hp-sdd!ncr-sd!ncrlnk!ncrcam!ncrcpx!craig From: craig@ncrcpx.UUCP (R. Craig Peterson) Newsgroups: comp.sources.d Subject: A perl program to change usg style dfs into Berkeley Message-ID: <1821621@ncrcpx.UUCP> Date: 5 Feb 88 16:51:47 GMT Reply-To: craig@ncrcpx.UUCP (R. Craig Peterson) Organization: NCR E&M Cambridge, Ohio Lines: 84 Keywords: perl source code 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 () 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)