[prev in list] [next in list] [prev in thread] [next in thread]
List: perl-win32-users
Subject: RE: is there a module or func which shows the free space
From: Mohammed Gazal <mgazal () interwoven ! com>
Date: 2003-06-25 2:43:58
[Download RAW message or body]
Thank you for all those who send me the code. All of them are helpful.
Thxs,
Mohammed Gazal.
> -----Original Message-----
> From: Trevor Joerges [SendMIME Software]
> [mailto:tjoerges@sendmime.com]
> Sent: Tuesday, June 24, 2003 7:22 PM
> To: Mohammed Gazal; perl-win32-users@listserv.ActiveState.com
> Subject: Re: is there a module or func which shows the free space
>
>
> RE: How do I avoid the DOS window when starting a perl scriptAnother
> alternative not mentioned is
> Win32::AdminMisc::GetDriveSpace(\\\\server\\drive\$). It's
> probably not as
> efficient as the other mentioned methods but you could
> iterate through all
> drive letters a-z and check their space.
>
> Here is some code I write to do this first reading in a list
> of machines in
> a flat text file. Please excuse the large paste of code. I
> plan to make this
> available from my web site when time permits. Hope this helps.
>
> ~~~~~~~~~~~~~~~~~
> use strict;
> use Win32::AdminMisc;
>
> $| = 1;
>
> if (@ARGV != 1) {
> print "\nUsage: report_drive_space.pl <file name>\n\n";
> exit 1;
> }
>
>
> #set global variables
> my @drives = ( a .. z );
> my $serverfile = $ARGV[0];
> my $total_servers = 0;
>
> # print report header
> $~ = "RESULTS_TOP";
> write;
>
> $~ = "RESULTS";
>
> open SERVER_FILE, "<$serverfile" || die "Unable to open
> server list file:
> $!\n";
> while (<SERVER_FILE>) {
> chomp $_;
> my $host = $_;
> uc $host;
> my $server = $host;
> foreach my $drive (@drives) {
> if ( ( $Total, $Free ) = Win32::AdminMisc::GetDriveSpace(
> "\\\\$server\\$drive\$" ) ) {
> if ($Free > 0) {
> $Used = $Total - $Free;
> $Used = comma_format($Used);
> $Free = comma_format($Free);
> $Total = comma_format($Total);
> add_to_global_used(uncomma_format($Used));
> add_to_global_free(uncomma_format($Free));
> add_to_global_total(uncomma_format($Total));
> %info = Win32::AdminMisc::GetVolumeInfo("\\\\$server\\$drive\$");
> write;
> }
> undef $host;
> }
> }
> $total_servers++;
> }
> close SERVER_FILE;
> print_footer();
>
> sub comma_format {
> my ($num) = @_;
> $num = scalar reverse $num;
> $num =~ s/\d{3}/$&,/g;
> $num = scalar reverse $num;
> $num =~ s/^,//;
> return $num;
> }
>
> sub uncomma_format {
> my ($num) = @_;
> $num =~ s/,//g;
> return $num;
> }
>
> sub add_to_global_used {
> my ($num) = @_;
> $global_used = $global_used + $num;
> }
>
> sub add_to_global_free {
> my ($num) = @_;
> $global_free = $global_free + $num;
> }
>
> sub add_to_global_total {
> my ($num) = @_;
> $global_total = $global_total + $num;
> }
>
> sub print_footer {
> $global_total = comma_format($global_total);
> $global_free = comma_format($global_free);
> $global_used = comma_format($global_used);
> print
> "-------------------------------------------------------------
> --------------
> ----------------------------------------\n\n";
> print <<" EOF";
> Total Servers: $total_servers
> Total Bytes: $global_total
> Total Free Bytes: $global_free
> Total Used Bytes: $global_used
>
> EOF
> }
>
>
> format RESULTS_TOP =
> @|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> ||||||||||||||
> |||||||||||||||||||||||||||||||||||||||
> "Disk Space Report Writer by Trevor Joerges"
> @|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> ||||||||||||||
> |||||||||||||||||||||||||||||||||||||||
> "http://www.sendmime.com"
> @|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> ||||||||||||||
> |||||||||||||||||||||||||||||||||||||||
> "tjoerges\@sendmime.com"
>
>
> Server Disk Space Report
> for:@>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>
> $now = scalar localtime ()
>
> --------------------------------------------------------------
> --------------
> ---------------------------------------
> @<<<<<<<<<<<<<<@|||||||||||@<<<<<<<<<<@<<<<<<<<<<<<<<<@<<<<<<<
> <<<<<@>>>>>>>>
> >>>>>>>@>>>>>>>>>>>>>>>@>>>>>>>>>>>>>>>
> Server,Drive,"FS Type",Volume,Serial,"Total Bytes","Free
> Bytes","Used Bytes"
> --------------------------------------------------------------
> --------------
> ---------------------------------------
> .
>
> format RESULTS =
> @<<<<<<<<<<<<<<@|||||||||||@<<<<<<<<<<@<<<<<<<<<<<<<<<@<<<<<<<
> <<<<<@>>>>>>>>
> >>>>>>>@>>>>>>>>>>>>>>>@>>>>>>>>>>>>>>>
> uc $host,uc
> $drive,$info{FileSystemName},$info{Volume},$info{Serial},$Tota
> l,$Free,$Used
> .
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
>
> ----- Original Message -----
> From: Mohammed Gazal
> To: 'perl-win32-users@listserv.ActiveState.com'
> Sent: Tuesday, June 24, 2003 7:04 PM
> Subject: is there a module or func which shows the free space
>
>
> Hello all,
>
> I have a script which shows me the free space of my drive like this
>
> my(@out) = `cmd /c "dir $drv:\\"`;
> foreach(@out){
> next if (!/bytes free/);
> $_ =~ s/\n/\s/gs;
> $space = (split(/\s+/, $_))[3];
> }
> $space =~ s|\,||g;
> return(0) if ($space == 0);
> return($space / 1024000);
> }
>
>
> iam using the dir command to get the space. Is there any
> perl module or
> function which does the same thing? Please let me know.
>
> Thxs,
>
> Mohammed Gazal.
>
>
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic