| Line 1... |
Line 1... |
| 1 |
#!/usr/bin/env perl
|
1 |
#!/usr/bin/env perl
|
| 2 |
use warnings;
|
2 |
use warnings;
|
| 3 |
use strict;
|
3 |
use strict;
|
| 4 |
|
4 |
|
| 5 |
# Description: Windows Drive Parition information
|
- |
|
| 6 |
|
- |
|
| 7 |
our $VERSION = '0.1.0';
|
5 |
use version ; our $VERSION = 'v1.0.0';
|
| 8 |
|
6 |
|
| - |
|
7 |
# Template for modules to be used in sysinfo
|
| - |
|
8 |
# Author: R. W. Rodolico
|
| - |
|
9 |
# Date: 2025-04-02
|
| - |
|
10 |
#
|
| 9 |
# This is a simple script to gather some basic information on drives
|
11 |
# This is a simple script to gather some basic information on drives
|
| 10 |
# on a Windows system
|
12 |
# on a Windows system
|
| - |
|
13 |
#
|
| - |
|
14 |
# Revision History
|
| - |
|
15 |
#
|
| - |
|
16 |
#
|
| 11 |
|
17 |
|
| 12 |
|
- |
|
| 13 |
# find our location and use it for searching for libraries
|
18 |
# find our location and use it for searching for libraries. library.pm must be in the same directory as the calling script
|
| - |
|
19 |
# or, if run interactively, in the parent of the modules
|
| 14 |
BEGIN {
|
20 |
BEGIN {
|
| 15 |
use FindBin;
|
21 |
use FindBin;
|
| 16 |
use File::Spec;
|
22 |
use File::Spec;
|
| - |
|
23 |
# prepend the bin directory and its parent
|
| 17 |
use lib File::Spec->catdir($FindBin::Bin);
|
24 |
use lib File::Spec->catdir($FindBin::Bin), File::Spec->catdir("$FindBin::Bin/..");
|
| 18 |
eval( 'use library;' );
|
25 |
eval( 'use library;' );
|
| 19 |
die "Could not find library.pm in the code directory\n" if $@;
|
26 |
die sprintf( "Could not find library.pm in %s, INC is %s\n", __FILE__, join( "\n", @INC ) ) if $@;
|
| 20 |
eval( 'use Data::Dumper;' );
|
- |
|
| 21 |
}
|
27 |
}
|
| 22 |
|
28 |
|
| - |
|
29 |
#####
|
| - |
|
30 |
##### Change these to match your needs
|
| - |
|
31 |
#####
|
| - |
|
32 |
|
| - |
|
33 |
# Make this a list of all the modules we are going to use. You can replace undef with the version you need, if you like
|
| - |
|
34 |
my $modulesList = {
|
| - |
|
35 |
'Data::Dumper' => undef,
|
| - |
|
36 |
'Win32::DriveInfo' => undef,
|
| - |
|
37 |
};
|
| - |
|
38 |
|
| - |
|
39 |
# hash of commands that are needed for the system. key is the name of the command and, in some cases, the value will become
|
| - |
|
40 |
# the full path (from which or where)
|
| 23 |
# check for valid OS.
|
41 |
my $commandsList = {
|
| - |
|
42 |
};
|
| - |
|
43 |
|
| - |
|
44 |
# list of operating systems this module can be used on.
|
| - |
|
45 |
my $osList = {
|
| 24 |
exit 1 unless &checkOS( { 'mswin32' => undef } );
|
46 |
'mswin32' => undef,
|
| - |
|
47 |
# 'freebsd' => undef,
|
| - |
|
48 |
# 'linux' => undef,
|
| - |
|
49 |
};
|
| 25 |
|
50 |
|
| 26 |
# check for required commands, return 2 if they don't exist. Enter an full list of all commands required. If one doesn't exist
|
- |
|
| 27 |
# script returns a 2
|
- |
|
| 28 |
#foreach my $command ( 'systeminfo' ) {
|
- |
|
| 29 |
# exit 2 unless $commands{$command} = &validCommandOnSystem( $command );
|
- |
|
| 30 |
#}
|
- |
|
| 31 |
# category we will use for all values found
|
51 |
# the category the return data should go into. See sysinfo for a list
|
| 32 |
# see sysinfo for a list of valid categories
|
- |
|
| 33 |
my $CATEGORY = 'diskinfo';
|
52 |
my $CATEGORY = 'diskinfo';
|
| 34 |
|
53 |
|
| - |
|
54 |
#####
|
| 35 |
use Win32::DriveInfo;
|
55 |
##### End of required
|
| - |
|
56 |
#####
|
| - |
|
57 |
|
| - |
|
58 |
# some variables needed for our system
|
| - |
|
59 |
my $errorPrepend = 'error: in ' . __FILE__; # this is prepended to any error messages
|
| - |
|
60 |
my @out; # temporary location for each line of output
|
| - |
|
61 |
|
| - |
|
62 |
# Try to load the modules we need. If we can not, then make a list of missing modules for error message.
|
| - |
|
63 |
for my $module ( keys %$modulesList ) {
|
| - |
|
64 |
eval ( "use $module;" );
|
| - |
|
65 |
push @out, "$errorPrepend Could not load $module" if $@;
|
| - |
|
66 |
}
|
| 36 |
|
67 |
|
| - |
|
68 |
if ( ! @out && ! checkOS ( $osList ) ) { # check if we are on an acceptible operating system
|
| - |
|
69 |
push @out, "$errorPrepend Invalid Operating System";
|
| - |
|
70 |
}
|
| - |
|
71 |
if ( !@out && ! validCommandOnSystem ( $commandsList ) ) {
|
| - |
|
72 |
push @out, "$errorPrepend Can not find some commands needed";
|
| - |
|
73 |
}
|
| - |
|
74 |
if ( !@out ) { # we made it, we have everything, so do the processing
|
| - |
|
75 |
#####
|
| - |
|
76 |
##### Your code starts here. Remember to push all output onto @out
|
| - |
|
77 |
#####
|
| - |
|
78 |
|
| 37 |
my @drives = Win32::DriveInfo::DrivesInUse();
|
79 |
my @drives = Win32::DriveInfo::DrivesInUse();
|
| - |
|
80 |
|
| 38 |
# print join( "\n", @drives ) . "\n";
|
81 |
foreach my $drive ( @drives ) {
|
| - |
|
82 |
push @out, sprintf( "%s\t%s\t%s\t%s", $CATEGORY, $drive, 'fstype', ( Win32::DriveInfo::VolumeInfo ( $drive ) )[3] );
|
| - |
|
83 |
push @out, sprintf( "%s\t%s\t%s\t%s", $CATEGORY, $drive, 'size', int( (Win32::DriveInfo::DriveSpace($drive))[5] / 1024 + 0.5 ) );
|
| - |
|
84 |
push @out, sprintf( "%s\t%s\t%s\t%s", $CATEGORY, $drive, 'used', int ( ( (Win32::DriveInfo::DriveSpace($drive))[5] - (Win32::DriveInfo::DriveSpace($drive))[6] ) / 1024 + .5) );
|
| - |
|
85 |
}
|
| - |
|
86 |
|
| - |
|
87 |
|
| - |
|
88 |
#####
|
| - |
|
89 |
##### Your code ends here.
|
| - |
|
90 |
#####
|
| - |
|
91 |
}
|
| 39 |
|
92 |
|
| 40 |
foreach my $drive ( @drives ) {
|
- |
|
| 41 |
printf( "%s\t%s\t%s\t%s\n", $CATEGORY, $drive, 'fstype', ( Win32::DriveInfo::VolumeInfo ( $drive ) )[3] );
|
93 |
# If we are testing from the command line (caller is undef), print the results for debugging
|
| 42 |
printf( "%s\t%s\t%s\t%s\n", $CATEGORY, $drive, 'size', int( (Win32::DriveInfo::DriveSpace($drive))[5] / 1024 + 0.5 ) );
|
- |
|
| 43 |
printf( "%s\t%s\t%s\t%s\n", $CATEGORY, $drive, 'used', int ( ( (Win32::DriveInfo::DriveSpace($drive))[5] - (Win32::DriveInfo::DriveSpace($drive))[6] ) / 1024 + .5) );
|
- |
|
| 44 |
}
|
- |
|
| 45 |
# in scalar, will simply return the short name. use 'scalar' to force that.
|
94 |
print join( "\n", @out ) . "\n" unless caller;
|
| 46 |
#printf( "%s\t%s\t%s\n", $CATEGORY, 'distribution', scalar Win32::GetOSName() );
|
95 |
# called by do, which has a value of the last assignment made, so make the assignment. The equivilent of a return
|
| 47 |
#printf( "%s\t%s\t%s\n", $CATEGORY, 'description', Win32::GetOSDisplayName() );
|
96 |
my $return = join( "\n", @out );
|
| 48 |
|
97 |
|
| 49 |
exit 0;
|
- |
|