Here's my script that works on Win32 computers. It uses Win32::DriveInfo to grab the stats, and logs them into a MySQL DB. (Ignore Net::MySQL stuff, DBI is better - but the script is old...)

#!/usr/bin/perl use strict; use Win32::DriveInfo; use Net::MySQL; use Sys::Hostname; my @drives; my ($TotalNumberOfFreeBytes, $TotalNumberOfBytes, $totalMB, $totalFree +MB, $UsedMB); my ($t, $date, $record_set, $record, $volume, $SQL, $host, $drive); my $mysql = Net::MySQL->new( hostname => 'host', # Default use UNIX socket database => 'hdd_capacity', user => 'user', password => 'pass' ); #Calculate the date for logging into database my ($sec,$min,$hour,$mday,$month,$year, $wday,$yday,$isdst) = localtim +e time; $month++; foreach $t ($mday, $month, $hour, $min, $sec) { if ($t < 10) {$t = '0' . $t;} } $year=substr($year,1); $year="20".$year if length($year)==2; $date="$year-$month-$mday"; $host = hostname; print "hostname = $host\n"; @drives = Win32::DriveInfo::DrivesInUse(); foreach $drive (@drives) { if (Win32::DriveInfo::DriveType($drive) == 3 ) #If the disk is HDD { $TotalNumberOfFreeBytes = (Win32::DriveInfo::DriveSpace($drive ) +)[6]; $TotalNumberOfBytes = (Win32::DriveInfo::DriveSpace($drive ))[5] +; $totalMB = int($TotalNumberOfBytes / 1048576); $totalFreeMB = int($TotalNumberOfFreeBytes / 1048576); $UsedMB = $totalMB - $totalFreeMB; print "$drive, $totalMB, $totalFreeMB\n"; #SELECT volume_id for current volume $SQL = "SELECT volume_id FROM hdd_info WHERE server_name = \'$ho +st\' AND volume_name = \'$drive\'"; $mysql->query($SQL); $record_set = $mysql->create_record_iterator; $record = $record_set->each; $volume = $record->[0]; print "Volume = $volume\n"; #Create SQL statement $SQL = "insert into hdd_usage values (\'$date\', \'$volume\', \' +$UsedMB\')"; $mysql->query($SQL); # Execute SQL statement - log the data die $mysql->get_error_message if $mysql->is_error; } } $mysql->close; #-----------------------------------------------------------------

--------------------------------
An idea is not responsible for the people who believe in it...


In reply to Re: Disk size manager in perl? by bofh_of_oz
in thread Disk size manager in perl? by tphyahoo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.