#!perl -w use Win32::AdminMisc 981228||die; use CGI qw /:standard -nph/; use DBI; use DBD::Chart; my $dbh = DBI->connect('dbi:Chart:'); $|++; $POST_MAX=100; $DISABLE_UPLOAD=1; print header(); print start_html(-title=>'*du',-bgcolor=>"#000099",-text=>"#FF9933",-l +ink=>"#FF3300",-alink=>"#FF3300",-vlink=>"#FF3300"); print small('data updated '.localtime(time)).br; #######################CONFIG HASH###################### my %macchine=( 'host01'=>qw[name1 10.0.0.1 c undef c:/ao/log], 'host02'=>qw[name2 10.0.0.2 e undef c:/ao/log], 'host03'=>qw[name3 10.0.0.3 h undef c:/ao/log], ); ####################################################### foreach my $mak(sort keys %macchine) { my $drv= $macchine{$mak}[2]; my $ip= $macchine{$mak}[1]; my $host= $macchine{$mak}[0]; my $ret = &du_pie_dsk($ip, $drv, $mak); print b("$mak $drv".':'); if (-e "$mak$drv\.png") { print img {src=>"$mak$drv\.png"} } else {print i("Warning: $mak image not found! $ret")} my $base_log; if ($macchine{$mak}[4]=~/^(\w):/i){$base_log = $1;} if ($base_log ne $drv) { print b("Log $base_log".':'); my $ret = &du_pie_dsk($ip, $base_log, $mak); if (-e "$mak$base_log\.png") { print img {src=>"$mak$base_log\.png"} } else {print i("Warning: $mak image not found! $ret")} } print br.hr; } sub du_pie_dsk{ my $ip=shift; my $dsk=shift; my $host=shift; my $str='\\\\'.$ip.'\\'.$dsk.'$'; my ($totale, $liberi); unless (($totale, $liberi)=Win32::AdminMisc::GetDriveSpace($str)){re +turn "Errore Win32::AdminMisc::GetDriveSpace : $^E"} my $occupati=($totale-$liberi); my $tot=Arrotonda_Mega($totale); my $lib=Arrotonda_Mega($liberi); my $occ=Arrotonda_Mega($occupati); $dbh->do("CREATE TABLE $host$dsk (region CHAR(20), sales INT)"); $sth = $dbh->prepare("INSERT INTO $host$dsk VALUES( ?, ?)"); $sth->execute("$lib free", $liberi); $sth->execute("$occ used", $occupati); my $now = localtime (time); $rsth = $dbh->prepare( "SELECT PIECHART FROM $host$dsk WHERE WIDTH=400 AND HEIGHT=130 AND TITLE = \'$host\' AND COLOR=(lpurple, blue) AND SIGNATURE=\'$now auto perl\' AND BACKGROUND=lgray"); $rsth->execute; $rsth->bind_col(1, \$buf); $rsth->fetch; open(OUTF, ">$host$dsk\.png"); binmode OUTF; print OUTF $buf; close(OUTF); } sub Arrotonda_Mega{ my( $size, $n ) =( shift, 0 ); ++$n and $size /= 1024 until $size < 1024; return sprintf "%.2f %s", $size, ( qw[ bytes Kb Mb Gb ] )[ $n ]; } # # simple piechart #

In reply to win32 disk usage CGI by Discipulus

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.