MS Perl question -- how to use hacked script to work correctly(was Question on loops and return values or sumpin)

From: James (djcameron60616_at_yahoo.com)
Date: 12/08/04


Date: 8 Dec 2004 11:59:05 -0800

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.



Relevant Pages

  • RE: How can I setup a an free disk space alarm...HELP!!!
    ... the disk space of all disk drives within managed computers. ... and red states for state monitoring of disk free space. ... You can modify the threshold values that the event rule uses to trigger ...
    (microsoft.public.windows.server.general)
  • Re: Hard drive does not stay defragged!
    ... Your free space at 17% is minimal and means that larger files can be ... Advanced and check the box before Compress contents to ... The Defrag seems to get to about 15%, then it ends, telling me it had ... My HD is a year old, 40 GB, partitoned into three drives. ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: winxp is using all of my hard drive space
    ... gerry that is my exact problem. ... how can i find what is taking the free space. ... system restore only takes ... Which drives are shown as Monitored and which as Turned Off? ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: Win XP takes more space on SATA than IDE
    ... To increase you free space on your C select Start, All Programs, ... Accessories, System Tools, Disk CleanUp, More Options, System Restore and ... > the RAM which is different in both PCs. ... >> Are the drives formatted as FAT32 or NTFS? ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Disk free space minimum threshold warning
    ... Size, and Free Space. ... disk space is being used. ... Which drives are shown as Monitored and which as Turned Off? ... remove all but the latest System Restore points? ...
    (microsoft.public.windowsxp.help_and_support)