D
delfuego
I have a script below that is supposed to read in a list of microsoft
servers, and output the disk space (current and last), dates
(beginning and ending), and compute space growth in value and
percentage; to output file. The question is this: how do I get the
correct looping going on in my for loops (one is not getting the
machines, the other is not getting the drive letters; as well as any
other problems you can point out. The files are listed below the
scriipt, although I plan to write out two additional columns, growth
value and growth rate.
ALL help is appreciated.
Thanks,
James
<script beow inline>
use lib "$ENV(HOME)/site/lib"; # occasionally perl whines about not
in a lib
no lib ".";
use warnings;
use Time::localtime; # needed for tm and using that to get dates
use Time::tm;
use Win32API::Resources; # needed for drives and disk space
our @drive = Win32API::Resources::GetDrives();
our %space = Win32API::Resources::GetDriveSpace("$let:\\");
our $file = (<SD>,"growth.cvs"); # output data file
our $file2 = (<SD>,"machines.cvs"); # input data file
our $let = ['A-Z']; # character value for drive letters
our $gvalue = 0; # difference, should be positive
our $curr = 0; # current disk space value
our $last = 0; # last disk space value
our $grate = 0; # growth rate percentage
our @line = ""; # was going to be used for file looping
our $edate = ""; # end date for run
our $sdate = ""; # start date for run
# Mind you, we still need to loop this through machines in a list, but
# this will supposedly loop through the letters in the GetDrives
returns
open (file2,"+<"); # open machines input file for read
while <file2> # loop while not eof in machines.cvs
{
foreach $machine (<file2>)
{
print "The following are valid disk drives: @drive\n";
foreach $let (@drive)
{
&space();
&growth();
}
}
}
close file2;
sub space()
# This will return the space details available from ShowKeys in three
line format
{
Win32API::Resources::ShowKeys("Drive Space:", 2, \%space);
}
sub growth()
# Reads in current value from file growth.cvs to be the value for
last, then
# the %DRVSpace becomes current's value. After this, the dates are
set and
# we start computing the growth, giving growth difference and
percentage.
# Finally, all details are written to the appended file.
{
open file or die "Cannot open data file for read\n";
while <file>
{
$sdate = (read(file,"$junk," ",$edate," ",$junk," ",$junk) =
split);
chop ($sdate);
$last = (read(file,"$junk," ",$junk," ",$junk," ",$curr) = split);
chop ($last);
}
close file;
# we have the last and sdate variables, now we need the others
my $edate = Time::tm(localtime(){$4,$5,$6});
$curr = %DRVSpace;
$last = eval { $curr / 5 }; # bogus value for testing, should be
file($curr)
# now we sart computing
$gvalue = eval { $curr - $last }; # growth rate difference
$grate = eval { ($gvalue / $last) * 100 }; # growth rate percentage
# time for a screen dump
print "Date: $edate";
print "Last: $last\tCurrent: $curr\tGrowth: $gvalue\tGrowth Rate:
$grate\n";
# now to dump everything to the file
open (file,"+>> ") or die "Cannot open data file for write\n";
while <file>
{
print (file,"\n$sdate $edate $last $curr");
}
close file;
}
<files>
machines.csv
---------------
snoopy
linus
charlie
lucy
pigpen
freida
growth.csv
servers, and output the disk space (current and last), dates
(beginning and ending), and compute space growth in value and
percentage; to output file. The question is this: how do I get the
correct looping going on in my for loops (one is not getting the
machines, the other is not getting the drive letters; as well as any
other problems you can point out. The files are listed below the
scriipt, although I plan to write out two additional columns, growth
value and growth rate.
ALL help is appreciated.
Thanks,
James
<script beow inline>
use lib "$ENV(HOME)/site/lib"; # occasionally perl whines about not
in a lib
no lib ".";
use warnings;
use Time::localtime; # needed for tm and using that to get dates
use Time::tm;
use Win32API::Resources; # needed for drives and disk space
our @drive = Win32API::Resources::GetDrives();
our %space = Win32API::Resources::GetDriveSpace("$let:\\");
our $file = (<SD>,"growth.cvs"); # output data file
our $file2 = (<SD>,"machines.cvs"); # input data file
our $let = ['A-Z']; # character value for drive letters
our $gvalue = 0; # difference, should be positive
our $curr = 0; # current disk space value
our $last = 0; # last disk space value
our $grate = 0; # growth rate percentage
our @line = ""; # was going to be used for file looping
our $edate = ""; # end date for run
our $sdate = ""; # start date for run
# Mind you, we still need to loop this through machines in a list, but
# this will supposedly loop through the letters in the GetDrives
returns
open (file2,"+<"); # open machines input file for read
while <file2> # loop while not eof in machines.cvs
{
foreach $machine (<file2>)
{
print "The following are valid disk drives: @drive\n";
foreach $let (@drive)
{
&space();
&growth();
}
}
}
close file2;
sub space()
# This will return the space details available from ShowKeys in three
line format
{
Win32API::Resources::ShowKeys("Drive Space:", 2, \%space);
}
sub growth()
# Reads in current value from file growth.cvs to be the value for
last, then
# the %DRVSpace becomes current's value. After this, the dates are
set and
# we start computing the growth, giving growth difference and
percentage.
# Finally, all details are written to the appended file.
{
open file or die "Cannot open data file for read\n";
while <file>
{
$sdate = (read(file,"$junk," ",$edate," ",$junk," ",$junk) =
split);
chop ($sdate);
$last = (read(file,"$junk," ",$junk," ",$junk," ",$curr) = split);
chop ($last);
}
close file;
# we have the last and sdate variables, now we need the others
my $edate = Time::tm(localtime(){$4,$5,$6});
$curr = %DRVSpace;
$last = eval { $curr / 5 }; # bogus value for testing, should be
file($curr)
# now we sart computing
$gvalue = eval { $curr - $last }; # growth rate difference
$grate = eval { ($gvalue / $last) * 100 }; # growth rate percentage
# time for a screen dump
print "Date: $edate";
print "Last: $last\tCurrent: $curr\tGrowth: $gvalue\tGrowth Rate:
$grate\n";
# now to dump everything to the file
open (file,"+>> ") or die "Cannot open data file for write\n";
while <file>
{
print (file,"\n$sdate $edate $last $curr");
}
close file;
}
<files>
machines.csv
---------------
snoopy
linus
charlie
lucy
pigpen
freida
growth.csv