Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^4: Trying to get drive space info on remote Windows servers

by Cloudster (Novice)
on Feb 19, 2010 at 06:12 UTC ( #824099=note: print w/replies, xml ) Need Help??

in reply to Re^3: Trying to get drive space info on remote Windows servers
in thread Trying to get drive space info on remote Windows servers

The thought plickens!

Here's the latest generation of the code:
use Win32::DriveInfo; use constant { SECTORS_PER_CLUSTER => 0, BYTES_PER_SECTOR => 1, FREE_CLUSTERS => 2, TOTAL_CLUSTERS => 3, BYTES_FREE_4_CALLER => 4, TOTAL_BYTES => 5, TOTAL_FREE => 6, }; #$sql = "\\\\server01\\d\$"; $sql = "c:"; print "$sql\n"; print "Drive Free Tot PctFree\n"; my @info = Win32::DriveInfo::DriveSpace($sql) ; print "$^E\n"; # or die "DriveSpace failed with error: $^E"; printf "%.3f GB free of total %.3f GB\n", $info[ TOTAL_FREE ] / 1000**3, $info[ TOTAL_BYTES ] / 1000**3;
And here's the output of two runs:
c:\Perl> \\sql-01\d$ Drive Free Tot PctFree 0.000 GB free of total 0.000 GB c:\Perl> c: Drive Free Tot PctFree The specified procedure could not be found 31.283 GB free of total 74.444 GB c:\Perl>dir Volume in drive C is cMore Volume Serial Number is A07E-ED9D Directory of c:\Perl 02/18/2010 10:59 PM <DIR> . 02/18/2010 10:59 PM <DIR> .. 05/30/2008 03:51 PM <DIR> bin 05/30/2008 03:51 PM <DIR> eg 05/30/2008 03:51 PM <DIR> etc 05/30/2008 03:52 PM <DIR> html 05/30/2008 03:51 PM <DIR> lib 05/30/2008 03:51 PM <DIR> man 05/30/2008 03:51 PM <DIR> site 02/18/2010 10:58 PM 629 drivelist.bak 02/18/2010 10:59 PM 628 2 File(s) 1,257 bytes 9 Dir(s) 33,590,083,584 bytes free
So if I point it to my local drive, I get an error condition but I get correct results. If I point it to a server $root share, I get no results but nothing in the error string. And I tried running it against my local machine as a \\pcname\c$ and got the same result as a remote server, zeroes for space and no error.

I noticed the discrepency on disk space. Turns out I need to divide by 1000**3 rather than 1024**3. Easy fix there. I have a couple of thoughts that I'll try tomorrow when I'm in the office.

I should have mentioned the Perl version that I'm running is:
c:\Perl>perl -v This is perl, v5.10.0 built for MSWin32-x86-multi-thread (with 5 registered patches, see perl -V for more detail) Copyright 1987-2007, Larry Wall Binary build 1003 [285500] provided by ActiveState http://www.ActiveSt Built May 13 2008 16:52:49
I should probably look at an update tomorrow, but I don't think that's the issue. My PC is XP Pro SP3. I'm logged on as a general user but running a command prompt session as my network admin login, so if I do a 'dir \\server01\d$', I see results just fine.

Replies are listed 'Best First'.
Re^5: Trying to get drive space info on remote Windows servers
by BrowserUk (Pope) on Feb 19, 2010 at 09:29 UTC

    The problem is the regex on line 127 of

    $drive =~ s/^(\\\\\w+\\\w+\$?)(\\)?$/$1\\/;

    It doesn't allow for '-' in machine or path names. Switching that (and the 3 other occurances in the file) to

    $drive =~ s/^(\\\\[^\\]+\\[^\\]+\$?)(\\)?$/$1\\/;

    Allows the DriveSpace() call to work. At least using UNCs local on my machine. I haven't tested the other calls and that regex could probably be tighten back up a little.

    It would also be good if you reported the problem back to the module's author. Then he can decide how much tighter to make it and test the other occurences.

    You could also suggest changing all the occurances of return undef if/unless ...

    to return if/unless ....

    That'll ensure that the right flavour of undef is returned whatever the context, and allow the or die ... idiom to work properly in calling code.

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Thank you! I'll give it a shot later today. It's definitely an issue as all of our servers contain hyphens, it should have occurred to me that it could be an issue.

      Unfortunately I don't think contacting the author will do much good, his site is a .ru and hasn't been updated in a decade. But I'll give it a shot and we'll see what happens.
        Beauty! It works great! Now I just need to package it pretty in to a subroutine and integrate it with the rest of my code.

        I'll try to contact the author, if I don't hear back from him in a few weeks I'll post the update. All I changed was the regex expressions, I'm not going to touch the other changes that you recommend right now.

        Thanks again, all you monks!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://824099]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2019-06-17 04:47 GMT
Find Nodes?
    Voting Booth?
    Is there a future for codeless software?

    Results (76 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!