home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_04 / 8n04126a < prev    next >
Text File  |  1990-03-20  |  2KB  |  58 lines

  1. *****Listing 1*****
  2.  
  3.  
  4.  
  5.    #!/usr/local/bin/perl
  6.    eval    "exec /usr/local/bin/perl -S $0    $*"
  7.        if $running_via_sh;
  8.    # A cute Berkeley style df formatter    for those running USG df
  9.    # Do    what you want with it; it's yours.
  10.    # R.    Craig Peterson,    N8INO
  11.    $fs=join(' ',@ARGV);
  12.    open(Df, "df    -t $fs|") || die "Can't    run df.";
  13.  
  14.    format top =
  15.    Filesystem        kbytes    used  avail capacity  iused   ifree %iused Device
  16.    format STDOUT =
  17.    @<<<<<<<<<<<<<< @>>>>>> @>>>>>> @>>>>>    @>%   @>>>>>  @>>>>>    @>% @<<<<<<<<<<<<<<
  18.    $fs           $kbytes $used   $avail  $capacity $iused $inodes $piused $name
  19.  
  20.    while (<Df>)    {
  21.        if (/total blocks/) {
  22.            ($d,$tblocks,$d,$d,$tinodes,$d) = split(' ');
  23.            $tinodes *= 8;
  24.            $kbytes = $tblocks /    2;
  25.            $used = ($tblocks - $blocks)    / 2;
  26.            $avail = $blocks / 2;
  27.            $capacity = int(100 - ($blocks / $tblocks * 100));
  28.            $iused = $tinodes - $inodes;
  29.            $piused = int($iused    / $tinodes * 100);
  30.            write;
  31.            $tot_kbytes += $kbytes;
  32.            $tot_used +=    $used;
  33.            $tot_avail += $avail;
  34.            $tot_iused += $iused;
  35.            $tot_inodes += $inodes;
  36.            $tot_tinodes    += $tinodes;
  37.        } else {
  38.            s/\(\s*/ \(/;
  39.            s/\s*\)/\)/;
  40.            ($fs,$name,$blocks,$d,$inodes,$d) = split;
  41.            $name =~ s![(): \t]|/dev/dsk/!!g;
  42.        }
  43.    }
  44.    if ($#ARGV <    0) {
  45.        $kbytes = $tot_kbytes;
  46.        $used = $tot_used;
  47.        $avail = $tot_avail;
  48.        $capacity = int(100 - ($avail / $kbytes * 100));
  49.        $iused = $tot_iused;
  50.        $inodes = $tot_inodes;
  51.        $tinodes = $tot_tinodes;
  52.        $piused = int($iused    / $tinodes * 100);
  53.        $fs = 'Totals:';
  54.        $name = '';
  55.        write;
  56.    }
  57.  
  58.