Subversion Repositories camp_sysinfo_client_3

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
55 rodolico 1
#!/usr/bin/env perl
2
use warnings;
3
use strict;  
4
 
5
# Description: Disk usage for BSD Unix systems
6
 
57 rodolico 7
our $VERSION = '1.2';
55 rodolico 8
 
9
# BSD disks module for sysinfo client
10
# Author: R. W. Rodolico
11
# Date:  2017-11-24
12
 
56 rodolico 13
# gets information on disks. Returns them as a hash
55 rodolico 14
# uses standard df -kT and parses the output
15
# skips anything that does not have a device with /dev in it
16
# assumes the structure of the output is:
17
# device fstype size usedSpace availableSpace percentSpace mountPoint
18
# however, the output can sometimes wrap to multi lines, especially if the 
19
# device is long. So, we will replace all newlines with spaces, then 
20
# remove space duplications, then split on spaces and process each item in
21
# turn.
22
# NOTE: this will totally break if you have spaces in your mount point
23
 
24
BEGIN {
25
   push @INC, shift;
26
}
27
 
28
use library;
29
 
30
# the commands this script will use
31
my %commands = ( 
32
                  'sysctl' => ''
33
               );
34
 
35
# check the commands for validity
36
foreach my $command ( keys %commands ) {
37
   $commands{$command} = &validCommandOnSystem( $command );
38
}
39
 
57 rodolico 40
exit 1 unless $commands{'sysctl'};
56 rodolico 41
 
42
my $temp;
43
my $device;
44
my @temp;
45
my $CATEGORY = 'diskinfo';
55 rodolico 46
 
56 rodolico 47
 
55 rodolico 48
$temp = getSysctlParameter( $commands{ 'sysctl' }, 'kern.disks' );
49
my @disks =  split( /\s+/, $temp );
56 rodolico 50
foreach $device ( @disks ) {
55 rodolico 51
   $temp = qx( diskinfo $device );
52
   chomp $temp;
53
   my @info =  split( /\s+/, $temp );
54
   $temp = $info[2] / 1024;
56 rodolico 55
   print "$CATEGORY\t/dev/$device\tsize\t$temp\n";
55 rodolico 56
}
57