Thread Einfache Linux-Ausgabe "df -k" (15 answers)
Opened by Gast at 2006-12-15 20:40

bloonix
 2006-12-15 22:57
#28798 #28798
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Benoetigte Module:

CPAN:Sys::Statistics::Linux
CPAN:HTML::Template
CPAN:CGI

diskusage.cgi
Code: (dl )
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
Code: (dl )
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 CPAN: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.

View full thread Einfache Linux-Ausgabe "df -k"