#!/usr/bin/perl -w # (C) 2007-2020 Pavel Polyakov ########################## my $list=''; for(@ARGV){$list.=" '$_'"}; our @DFdata=(); #our %DFkeys=(); our @COLS=qw/ filesystem type avg newfs 1k-blocks 1024-blocks used avail available capacity use% iused ifree %iused iuse% mounted /; sub process_df($){ my $cmd=shift; my $line=0; my %hdr=(); my @colname=(); my @keyname=(); my @DF=`$cmd`; my $last=''; foreach (@DF) { chomp; next if /^\s*$/; @_=split/\s+/, "$last$_"; if(scalar @_ < 2) { # linux df -T $last=$_; next; } $last=''; if(!$line) { # header for my $ncol (0..scalar @_) { my $colname=$_[$ncol]; next unless defined $colname; $colname=undef if $colname=~/^on$/; next unless defined $colname; $colname[$ncol]=$colname; my $key=lc $colname; if($colname=~/(1k|1024)-blocks/i) { $key='1k-blocks'; } $keyname[$ncol]=$key; #$DFkeys{$key}=$colname; $DFdata[0]->{$key}=$colname; #print "$ncol: $key \t$colname[$ncol]\n"; } } else { # data for my $ncol (0..scalar @_) { my $key=$keyname[$ncol]; next unless defined $key; $DFdata[$line]->{$key}=$_[$ncol]; } } $line++; } } # process_df $DFdata[0]={ 'avg'=>'Avg,K', 'newfs'=>'newfs' }; process_df("df -ki $list"); process_df("df -k $list") unless defined($DFdata[0]{used}); $DFdata[0]->{mounted} = "Mounted on"; our %W; # max col width for my $line (0..scalar @DFdata){ my $DF=$DFdata[$line]; # hash #my $fs=$DFdata[$line]{filesystem}; my $fs=$DF->{filesystem}; next unless defined $fs; next if $fs=~/^\w*procfs|^(dev|fdesc)fs/; if($line) { # calc avg/newfs my $iused =$DF->{'iused'}; if ($iused>0) { $DF->{avg} = int($DF->{'used'} / $iused + 0.5); $DF->{newfs} = int($DF->{'1k-blocks'} / ($iused+$DF->{ifree})); } } for my $key (keys %$DF) { my $w=length(sprintf "%s",$DF->{$key}); $W{$key}=$w if !defined($W{$key}) || $W{$key} < $w; #print "$key:$w\n"; } # my $o="$fs $DF->{avg} $DF->{newfs} "; # print "$o\n"; } for my $line (0..scalar @DFdata){ my $DF=$DFdata[$line]; # hash #my $fs=$DFdata[$line]{filesystem}; my $fs=$DF->{filesystem}; next unless defined $fs; next if $fs=~/^\w*procfs|^(dev|fdesc)fs/; my $o=''; for my $key (@COLS) { next unless defined $DF->{$key}; my $w=$W{$key}+1; if(!defined $w) { print "\t\t$key - no width!\n"; } $o.=sprintf("\%-${w}s", $DF->{$key}); } # my $o="$fs $DF->{avg} $DF->{newfs} "; print "$o\n"; } __END__ my $df='df -ki '; for(@ARGV){$df.=" '$_'"}; @DFF=`$df`;foreach (@DFF) { #next if !/^\/dev|used|mfs|cam/; next if /^\w*procfs|^(dev|fdesc)fs/; chomp; $o=$_; @_=split/\s+/; $bt=$_[1]; $bu=$_[2]; $iused=$_[5]; $ifree=$_[6]; $act=($iused>0)? sprintf("%-7.0f", $bu/$iused) : "Avg,K "; $org=($iused>0)? sprintf("%-7.0f", $bt/($iused+$ifree)) : "newfs "; print "${act}${org}$o\n"} __END__ 0 1 2 3 4 5 6 7 8 Filesystem 1024-blocks Used Avail Capacity iused ifree %iused Mounted on /dev/ad8s1d 82473779 38031533 37844344 50% 685997 4649617 13% /home Filesystem 1024-blocks Used Avail Capacity iused ifree %iused Mounted on /dev/mirror/dom3 2070548 1850792 54116 97% 14322 90636 14% / linux# df -T Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/sdb4 ext3 452899944K 174286840K 255937548K 41% / /dev/sdb1 ext3 98165K 19081K 74016K 21% /boot /dev/sda1 ext3 486779392K 254451696K 207962592K 56% /BAK tmpfs tmpfs 16394008K 0K 16394008K 0% /dev/shm hp160:/TRANSFER nfs 18469952K 16885056K 107328K 100% /HT