Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Disk size manager in perl?

by bofh_of_oz (Hermit)
on Aug 04, 2005 at 14:48 UTC ( #480852=note: print w/replies, xml ) Need Help??

in reply to Disk size manager in perl?

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...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://480852]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2018-03-22 10:18 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (273 votes). Check out past polls.