Benoetigte Module:
Sys::Statistics::Linux
HTML::Template
CGI
diskusage.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 
use strict;
use warnings;
use CGI::Carp qw(fatalsToBrowser);
use HTML::Template;
use Sys::Statistics::Linux::DiskUsage;
my $lxs   = new Sys::Statistics::Linux::DiskUsage;
my $usage = $lxs->get;
my $tmpl  = HTML::Template->new(filename => './diskusage.tmpl');
my @data;
foreach my $disk (sort keys %{$usage}) {
   $usage->{$disk}->{name} = $disk;
   push @data, $usage->{$disk};
}
$tmpl->param(DISKUSAGE => \@data);
print "Content-Type: text/html\n\n", $tmpl->output;
 
 
diskusage.tmpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
   <title>Disk Usage</title>
   <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
   <style type="text/css">
      .table { width: 60%; border-collapse: collapse; }
      .lcol  { width: 10%; border: 1px solid  text-align: left; }
      .rcol  { width: 10%; border: 1px solid  text-align: right; }
   </style>
</head>
<body>
<table class="table">
   <tr>
      <th class="lcol">NAME</th>
      <th class="lcol">TOTAL</th>
      <th class="lcol">USAGE</th>
      <th class="lcol">FREE</th>
      <th class="lcol">USAGE%</th>
      <th class="lcol">MOUNT POINT</th>
   <TMPL_LOOP NAME="DISKUSAGE">
   </tr><tr>
      <td class="lcol"><TMPL_VAR NAME="name"></td>
      <td class="rcol"><TMPL_VAR NAME="total"></td>
      <td class="rcol"><TMPL_VAR NAME="usage"></td>
      <td class="rcol"><TMPL_VAR NAME="free"></td>
      <td class="rcol"><TMPL_VAR NAME="usageper"></td>
      <td class="lcol"><TMPL_VAR NAME="mountpoint"></td>
   </TMPL_LOOP>
   </tr>
</table>
</body>
</html>
 
 
Eventuell laesst sich das sogar mit 
HTML::Template::Compiled besser lösen. :)
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.