Rev 237 | Blame | Last modification | View Log | Download | RSS feed
#!/usr/bin/env perl
use warnings;
use strict;
# Description: Disk usage for BSD Unix systems
our $VERSION = '1.3';
# BSD disks module for sysinfo client
# Author: R. W. Rodolico
# Date: 2017-11-24
# gets information on disks. Returns them as a hash
# uses standard df -kT and parses the output
# skips anything that does not have a device with /dev in it
# assumes the structure of the output is:
# device fstype size usedSpace availableSpace percentSpace mountPoint
# however, the output can sometimes wrap to multi lines, especially if the
# device is long. So, we will replace all newlines with spaces, then
# remove space duplications, then split on spaces and process each item in
# turn.
# NOTE: this will totally break if you have spaces in your mount point
#
# v1.3 20180424 RWR
# Fixed bug when diskinfo generates an error. Will still send error
# to STDERR, but will not break program.
BEGIN {
push @INC, shift;
}
use library;
exit 1 unless &getOperatingSystem() =~ m/bsd/i;
# the commands this script will use
my %commands = (
'sysctl' => ''
);
# check the commands for validity
foreach my $command ( keys %commands ) {
$commands{$command} = &validCommandOnSystem( $command );
}
exit 1 unless $commands{'sysctl'};
my $temp;
my $device;
my @temp;
my $CATEGORY = 'diskinfo';
$temp = getSysctlParameter( $commands{ 'sysctl' }, 'kern.disks' );
my @disks = split( /\s+/, $temp );
foreach $device ( @disks ) {
next unless eval { $temp = qx( diskinfo $device ); };
chomp $temp;
my @info = split( /\s+/, $temp );
$temp = $info[2] / 1024;
print "$CATEGORY\t/dev/$device\tsize\t$temp\n";
}