home *** CD-ROM | disk | FTP | other *** search
- #!/sbin/sh
-
-
- #ident "@(#)/sbin/dfspace.sl 1.1 4.0 12/08/90 32874 AT&T-USL"
-
- #
- # dfspace - d(isk) f(ree) space
- # Calculate the available disk space in all mounted filesystems
- # with the exception of pseudo file systems such as /proc and /dev/df.
- #
- # Alternately, report on filesystems/devices specified on cmd-line.
- # Filesystem may be 1K bytes/block, but, df uses 512 bytes/block.
- #
-
- /sbin/df -t $* | awk '
- BEGIN { FS=":"; free = -1; Blksize=512; Mbyte=1048576; CONST = Blksize / Mbyte }
- {
- if (free == -1) { # free is toggled every other line.
- split($1,fsptr,"("); FSYS=fsptr[1]
- if (NF == 3) {
- split($3,freeptr," "); free=freeptr[1]+0
- } else {
- split($2,freeptr," "); free=freeptr[1]+0
- }
- if( free == 0 && substr(freeptr[1],1,1) != "0" ) {
- free = -1; next
- }
- next
- }
- split($2,allocptr," "); alloc = allocptr[1]+0
- if (alloc == 0) alloc = 1; # avoid division by zero
- TFREE= (free * CONST) - .005 # force rounding down.
- TALLOC= (alloc * CONST) - .005 # force rounding down.
- PCT=free * 100 / alloc
- if (TFREE < 0) TFREE=0
- if (TALLOC < 0) TALLOC=0
-
- if (FSYS !~ /^\/proc/ && FSYS !~ /^\/dev\/fd/)
- printf ("%s:\tDisk space: %#6.2f MB of %#6.2f MB available (%#5.2f%%).\n", FSYS, TFREE, TALLOC, PCT)
- Cumfree += free; Cumalloc += alloc;
- free = -1 # reset flag/variable for next set of two lines
- }
- END {
- if (Cumalloc > 0) {
- CumPct=Cumfree * 100 / Cumalloc
- Cumfree= (Cumfree * CONST) - .005 # force rounding down.
- Cumalloc= (Cumalloc * CONST) - .005 # force rounding down.
- printf ("\nTotal Disk Space: %#6.2f MB of %#6.2f MB available (%#5.2f%%).\n", Cumfree, Cumalloc, CumPct)
- }
- }'
-
- # end of disk space calculation.
-