home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 4.ddi / sbin / dfspace < prev    next >
Encoding:
Text File  |  1990-12-08  |  1.6 KB  |  53 lines

  1. #!/sbin/sh
  2.  
  3.  
  4. #ident    "@(#)/sbin/dfspace.sl 1.1 4.0 12/08/90 32874 AT&T-USL"
  5.  
  6. #
  7. # dfspace - d(isk) f(ree) space
  8. # Calculate the available disk space in all mounted filesystems
  9. # with the exception of pseudo file systems such as /proc and /dev/df.
  10. # Alternately, report on filesystems/devices specified on cmd-line.
  11. #   Filesystem may be 1K bytes/block, but, df uses 512 bytes/block.
  12. #
  13.  
  14. /sbin/df -t $* | awk '
  15. BEGIN { FS=":"; free = -1; Blksize=512; Mbyte=1048576; CONST = Blksize / Mbyte }
  16. {
  17.   if (free == -1) {    # free is toggled every other line.
  18.     split($1,fsptr,"("); FSYS=fsptr[1]
  19.     if (NF == 3) {
  20.         split($3,freeptr," "); free=freeptr[1]+0
  21.     } else {
  22.         split($2,freeptr," "); free=freeptr[1]+0
  23.     }
  24.     if( free == 0 && substr(freeptr[1],1,1) != "0" ) {
  25.         free = -1; next
  26.     }
  27.     next
  28.   }
  29.   split($2,allocptr," "); alloc = allocptr[1]+0
  30.   if (alloc == 0) alloc = 1;            # avoid division by zero
  31.   TFREE= (free * CONST) - .005            # force rounding down.
  32.   TALLOC= (alloc * CONST) - .005        # force rounding down.
  33.   PCT=free * 100 / alloc
  34.   if (TFREE < 0) TFREE=0
  35.   if (TALLOC < 0) TALLOC=0
  36.  
  37.   if (FSYS !~ /^\/proc/ && FSYS !~ /^\/dev\/fd/) 
  38.     printf ("%s:\tDisk space: %#6.2f MB of %#6.2f MB available (%#5.2f%%).\n", FSYS, TFREE, TALLOC, PCT)
  39.   Cumfree += free; Cumalloc += alloc;
  40.   free = -1    # reset flag/variable for next set of two lines
  41. }
  42. END {
  43.     if (Cumalloc > 0) {
  44.     CumPct=Cumfree * 100 / Cumalloc
  45.     Cumfree= (Cumfree * CONST) - .005    # force rounding down.
  46.     Cumalloc= (Cumalloc * CONST) - .005    # force rounding down.
  47.     printf ("\nTotal Disk Space: %#6.2f MB of %#6.2f MB available (%#5.2f%%).\n", Cumfree, Cumalloc, CumPct)
  48.     }
  49. }'
  50.  
  51. # end of disk space calculation.
  52.