Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to get this script to work to monitor disk space

Status
Not open for further replies.

cfd963

IS-IT--Management
Oct 28, 2011
1
US
I'm really new to scripting, however, at my old place we had a script that we converted to exe and installed as a service that would email us a summary of our disk space for the specified servers. I have the scripts, but they don't seem to be working at my new place.

Script is below. Whenever I try to convert it to exe using perl2exe, it doesn't seem to like the first two use statements. If I take them out, I don't get the errors on conversion, but when I run the exe, nothing ever happens. I have also verified SMTP is working on the server I am attempting to run this from. Any help would be greatly appreciated, I'm beating my head against the wall here!

#!/usr/bin/perl

use strict;

use Win32::OLE qw( in );

my %Machines;
my $configfile = shift;
my $logfile = 'drivesum.log';

open(CONFIG, "$configfile");

my $config = join ', <CONFIG>;
my @config = split "\n" , $config;

foreach my $host ( @config ) {
my @confdata = split ":", $host;
my $serv = shift @confdata;
$Machines{$serv} = \@confdata;
}

my @Machines = keys(%Machines);
my $pagetrack;

while ( @Machines ) {
my $mail;
foreach my $Machine ( @Machines ) {
my $WMIServices = Win32::OLE->GetObject( "winmgmts://$Machine" ) || next;
my $Volumes = $WMIServices->InstancesOf( "Win32_LogicalDisk" );
my @drives = @{$Machines{$Machine}};
foreach my $drive ( @drives ) {
$drive =~ tr/[a-z]/[A-Z]/;
$drive .= ":";
foreach my $Volume ( in( $Volumes ) ) {
next unless ( $Volume->{Name} eq $drive );
next unless ( $Volume->{Size} > 0 );
my $name = $Volume->{Name};
my $percentused = 100-$Volume->{FreeSpace}/$Volume->{Size}*100;
$percentused =~ s/(\d+).\d+/$1/;
my $gigsize = $Volume->{Size}/1073741824;
$gigsize =~ s/(\d+.\d)\d+/$1/;
$mail .= "$Machine-$drive\($Volume->{VolumeName}\)-$percentused\% full\n";
}
}
}

my @sorted_mail = split("\n", $mail);
@sorted_mail = sort(@sorted_mail);

my $line_num;
my $new_mail;
for($line_num = 0; $line_num <= $#sorted_mail; $line_num++) {
$new_mail .= "$sorted_mail[$line_num]\n";
}

if ( $new_mail ) {
open(LOGFILE, ">>$logfile");
print LOGFILE "\n\n", scalar localtime(), "\n\n";
print LOGFILE "$new_mail\n";
sendmail($new_mail)
}

close(LOGFILE);
sleep(7200);

}


sub sendmail {
my $message = shift;
my $mailer = Win32::OLE->new('CDO.Message') or die "cant open mailer $!";
$mailer->LetProperty("Subject", 'Drivespace Summary');
$mailer->LetProperty("From", 'itsupportgroup@intren.com');
$mailer->LetProperty("To", 'jwenzel@intren.com');
$mailer->LetProperty("TextBody", "$message");
$mailer->Invoke("Send");
}
 
Have you tried running the code through a xxx.pl file and seeing what errors are generated?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top