df.squeeze.pl

I don’t like the way df looks, not even df -h.


$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_pecan-root
                      448G  6.5G  419G   2% /
tmpfs                 1.9G   76K  1.9G   1% /dev/shm
/dev/sda1             985M   74M  861M   8% /boot
/dev/mapper/mkm-mkm   443G  367G   55G  88% /mkm
/dev/mapper/pecanbackup-pecanbackuplv
                      1.8T  1.2T  605G  66% /mnt/localbackup
ns4300n0:/VOLUME1/BACKUP
                      2.8T  2.2T  584G  79% /mnt/ns4300n0
ns4300n1:/VOLUME1/MUSIC
                      2.8T 1008G  1.8T  37% /mnt/music
ns4300n1:/VOLUME1/VIDEO
                      2.8T 1008G  1.8T  37% /mnt/video
/dev/md0              3.2T  2.2T  797G  74% /mnt/backups

I prefer this;


$ df.squeeze.pl 
Filesystem                            Size  Used Avail Use% Mounted
/dev/mapper/mkm-mkm                   443G  367G   55G  88% /mkm
/dev/mapper/pecanbackup-pecanbackuplv 1.8T  1.2T  605G  66% /mnt/localbackup
/dev/mapper/vg_pecan-root             448G  6.5G  419G   2% /
/dev/md0                              3.2T  2.2T  797G  74% /mnt/backups
/dev/sda1                             985M   74M  861M   8% /boot
ns4300n0:/VOLUME1/BACKUP              2.8T  2.2T  584G  79% /mnt/ns4300n0
ns4300n1:/VOLUME1/MUSIC               2.8T 1008G  1.8T  37% /mnt/music
ns4300n1:/VOLUME1/VIDEO               2.8T 1008G  1.8T  37% /mnt/video
tmpfs                                 1.9G   76K  1.9G   1% /dev/shm

and here’s the perl wrapper;


#!/usr/bin/perl

$d=`date +%Y%m%d-%H%M%S`;
chop $d;
$com="/bin/df -hP ";
foreach $arg(@ARGV) {
        $com .= $arg.' ';
}
#$o=`cat /tmp/dftest`;
$o=`$com`;

@lines=split("n",$o);
@out=();
$head='';
$n = $#lines;
@clen = (0,0,0,0,0,0,0);

for($i = 0 ; $i < = $n ; $i++) {
        $line = @lines[$i];
        $linep1 = @lines[$i+1];
        $ch1 = substr($line,0,1);
        $ch1p1 = substr($linep1,0,1);
        if ($ch1p1 eq ' ') {
                $line .= ' ' . $linep1;
                $i++;
        }
        @cols = split(" ", $line);
        $dev =   @cols[0];
        $sizes_h{$dev} =  @cols[1];
        $used_h{$dev}  =  @cols[2];
        $avail_h{$dev} = @cols[3];
        $usep_h{$dev} =  @cols[4];
        $mp_h{$dev} =    @cols[5];

        if ($i > 0) {
                push(@devs,   @cols[0]);
        }

        for($j = 0 ; $j < 6 ; $j++) {
                if (@clen[$j] < length(@cols[$j])) {
                        @clen[$j] = length(@cols[$j]);
                }
        }
}

sort @devs;

$fmt = "%-" . @clen[0] . 's ';
$fmt .= "%" . @clen[1] . 's ';
$fmt .= "%" . @clen[2] . 's ';
$fmt .= "%" . @clen[3] . 's ';
$fmt .= "%" . @clen[4] . 's ';
$fmt .= "%-sn";

$dev = "Filesystem";
printf($fmt, $dev, $sizes_h{$dev}, $used_h{$dev}, $avail_h{$dev}, $usep_h{$dev}, $mp_h{$dev});

#for($i = 0 ; $i <= $n ; $i++) {
#       $dev = @devs[$i];
foreach $dev(sort(@devs)) {
        printf($fmt, $dev, $sizes_h{$dev}, $used_h{$dev}, $avail_h{$dev}, $usep_h{$dev}, $mp_h{$de
v});
}