J
James
First off, thanks to all who replied to my original post, I will go
back and reply to each of you .. thank you for your time.
And to everyone else now here, thank you for your time.
I have altered a couple scripts to work in IndigoPerl and
Win32::Resources to accomplish a simple task - read in a list of
servers from a text file, query them for their drives and space on the
drives, and put all the information on space out to a second text file,
space delimited.
My questions are before the code:
The important question is this: How to get an array of drive letters in
use in a foreach loop, and associating that with a hash variable
returning strings.
Example: GetDrives expects a string or empty list, and with the
empty list a foreach loop spits out all drive letters.
Example: In using GetDriveSpace, it returns only the values for C:\
(or whatever ("x:\\") letter you feed it.
So the question is how to get this function (GetDriveSpace) to be
passed an array, essentially - is this impossible potentially because
of the module design? Resources.pm is the module used with this
script. ShowKeys is what returns total, used and free space -- so this
is a third factor in manipulating this array.
I'm really trying to get the values for used, total and free space -
and I'm not quite sure how to get at it, and this is already taking too
long for me to figure out.
Here is the code:
use lib "$ENV(HOME)/site/lib";
no lib ".";
use Win32::Resources;
use Win32API::Resources;
# use strict;
# use warnings;
my @Drives = Win32API::Resources::GetDrives();
my %DRVSpace = Win32API::Resources::GetDriveSpace("C:\\");
my $pathtofiles = "\\C:\\scripts\\";
my $pathtoserverslist = "\\\\xxxxxnnnnnn\\";
my $Threshold = "80";
my $last_updated = localtime (time);
my $GB = 1073741824;
open(HANDLE1,"machines.txt") || die "open: $!";
open(HANDLE2,">>growth.txt") || die "open: $!";
print "\n\nLast run: $last_updated\n";
print "The following are valid disk drives: @Drives\n";
while ($Driveinfo=<HANDLE1>)
{
chomp($Driveinfo);
# @Drivearray=split (/[\\+]/, $Driveinfo);
# ($Total, $Free) = Win32API::Resources::GetDriveSpace
("\\\\$Driveinfo\\");
my $Total = 15073741824;
my $Free = 12073741824;
if ($Total gt 0) # if ($Total)
{
$Growth = ($Total-$Free) / $GB;
$Utilpercentage = ($Total-$Free) * 100 / $Total;
$Total1 = $Total / $GB;
$Free1 = $Free / $GB;
$Used1 = ($Total-$Free) / $GB;
$Total1 = sprintf("%5.2f\n", "$Total1");
$Free1 = sprintf("%5.2f\n", "$Free1");
$Used1 = sprintf("%5.2f\n", "$Used1");
$Utilpercentage = sprintf("%5.2f\n", "$Utilpercentage");
iscritical();
# Writing out the result set for this server\\share combo.
# print HANDLE2 "@Drivearray[0], @Drivearray[2], $Utilpercentage,
$Free1, $Used1,
$Total1 ";
# If the $Total was empty then "N/A" is put in the fields
}
else
{
$Total1 ="N/A";
$Free1 = "N/A";
$Used1 = "N/A";
$Utilpercentage = "N/A";
print HANDLE2 "$Total $Free1 $Used1 $Utilpercentage $Growth\n";
}
printstats();
skey();
}
close(HANDLE1) || die "close0: $!";
close(HANDLE2) || die "close0: $!";
sub iscritical()
{
if ($Utilpercentage >=$Threshold)
{
print "!!Utilized percentage greater than threshold level!!\n";
}
else # non-critical level
{
print "Utilized percentage less than threshold level!\n";
}
}
sub printstats()
{
$T1 = sprintf("%5.2f","$Total1");
$T2 = sprintf("%5.2f","$Free1");
$T3 = sprintf("%5.2f","$Used1");
$T4 = sprintf("%5.2f","$Utilpercentage");
$T5 = sprintf("%5.2f","$Growth");
print "\n\t\t\tUtilized\tGrowth\n";
print "Total:\tFree:\tUsed:\tPercentage:\tRate:\n";
print "$T1\t$T2\t$T3\t $T4\t $T5\n";
print HANDLE2 "$T1 $T2 $T3 $T4 $T5\n";
}
sub skey()
{
my $num_keys = keys %DRVSpace;
print "\n\nNumber of keys in DRVSpace: $num_keys\n";
foreach $let (@Drives)
{
Win32API::Resources::ShowKeys("Drive Space:", 1, \%DRVSpace);
}
}
Thanks to all for their responses and time .. even if it takes me a
while to respond.
back and reply to each of you .. thank you for your time.
And to everyone else now here, thank you for your time.
I have altered a couple scripts to work in IndigoPerl and
Win32::Resources to accomplish a simple task - read in a list of
servers from a text file, query them for their drives and space on the
drives, and put all the information on space out to a second text file,
space delimited.
My questions are before the code:
The important question is this: How to get an array of drive letters in
use in a foreach loop, and associating that with a hash variable
returning strings.
Example: GetDrives expects a string or empty list, and with the
empty list a foreach loop spits out all drive letters.
Example: In using GetDriveSpace, it returns only the values for C:\
(or whatever ("x:\\") letter you feed it.
So the question is how to get this function (GetDriveSpace) to be
passed an array, essentially - is this impossible potentially because
of the module design? Resources.pm is the module used with this
script. ShowKeys is what returns total, used and free space -- so this
is a third factor in manipulating this array.
I'm really trying to get the values for used, total and free space -
and I'm not quite sure how to get at it, and this is already taking too
long for me to figure out.
Here is the code:
use lib "$ENV(HOME)/site/lib";
no lib ".";
use Win32::Resources;
use Win32API::Resources;
# use strict;
# use warnings;
my @Drives = Win32API::Resources::GetDrives();
my %DRVSpace = Win32API::Resources::GetDriveSpace("C:\\");
my $pathtofiles = "\\C:\\scripts\\";
my $pathtoserverslist = "\\\\xxxxxnnnnnn\\";
my $Threshold = "80";
my $last_updated = localtime (time);
my $GB = 1073741824;
open(HANDLE1,"machines.txt") || die "open: $!";
open(HANDLE2,">>growth.txt") || die "open: $!";
print "\n\nLast run: $last_updated\n";
print "The following are valid disk drives: @Drives\n";
while ($Driveinfo=<HANDLE1>)
{
chomp($Driveinfo);
# @Drivearray=split (/[\\+]/, $Driveinfo);
# ($Total, $Free) = Win32API::Resources::GetDriveSpace
("\\\\$Driveinfo\\");
my $Total = 15073741824;
my $Free = 12073741824;
if ($Total gt 0) # if ($Total)
{
$Growth = ($Total-$Free) / $GB;
$Utilpercentage = ($Total-$Free) * 100 / $Total;
$Total1 = $Total / $GB;
$Free1 = $Free / $GB;
$Used1 = ($Total-$Free) / $GB;
$Total1 = sprintf("%5.2f\n", "$Total1");
$Free1 = sprintf("%5.2f\n", "$Free1");
$Used1 = sprintf("%5.2f\n", "$Used1");
$Utilpercentage = sprintf("%5.2f\n", "$Utilpercentage");
iscritical();
# Writing out the result set for this server\\share combo.
# print HANDLE2 "@Drivearray[0], @Drivearray[2], $Utilpercentage,
$Free1, $Used1,
$Total1 ";
# If the $Total was empty then "N/A" is put in the fields
}
else
{
$Total1 ="N/A";
$Free1 = "N/A";
$Used1 = "N/A";
$Utilpercentage = "N/A";
print HANDLE2 "$Total $Free1 $Used1 $Utilpercentage $Growth\n";
}
printstats();
skey();
}
close(HANDLE1) || die "close0: $!";
close(HANDLE2) || die "close0: $!";
sub iscritical()
{
if ($Utilpercentage >=$Threshold)
{
print "!!Utilized percentage greater than threshold level!!\n";
}
else # non-critical level
{
print "Utilized percentage less than threshold level!\n";
}
}
sub printstats()
{
$T1 = sprintf("%5.2f","$Total1");
$T2 = sprintf("%5.2f","$Free1");
$T3 = sprintf("%5.2f","$Used1");
$T4 = sprintf("%5.2f","$Utilpercentage");
$T5 = sprintf("%5.2f","$Growth");
print "\n\t\t\tUtilized\tGrowth\n";
print "Total:\tFree:\tUsed:\tPercentage:\tRate:\n";
print "$T1\t$T2\t$T3\t $T4\t $T5\n";
print HANDLE2 "$T1 $T2 $T3 $T4 $T5\n";
}
sub skey()
{
my $num_keys = keys %DRVSpace;
print "\n\nNumber of keys in DRVSpace: $num_keys\n";
foreach $let (@Drives)
{
Win32API::Resources::ShowKeys("Drive Space:", 1, \%DRVSpace);
}
}
Thanks to all for their responses and time .. even if it takes me a
while to respond.