I took the liberty of expanding on this and came up with a useful top-like script (including filter links and formatted fields):
#!/usr/bin/perl -w
use strict;
use CGI 'param';
use CGI::Push qw(:standard);
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
do_push(
-nph => 0,
-delay => 2,
-next_page => sub {
my($q, $count) = @_;
my @return;
my $command = "ps -auxwr";
$command .= " -U ".getpwuid(param("uid"))
if param("uid") =~ /^[0-9]+$/;
my @lines = split /\n/, `$command`;
my @header = split /\s+/, shift @lines;
my %format = (
"USER" => sub {
my($value) = @_;
my $uid = getpwnam($value);
return $value if ($uid == param("uid") &&
defined param("uid"));
return "<a href=\"$ENV{SCRIPT_NAME}?uid=$uid\">$value<
+/a>";
},
"\%CPU" => sub {
my($value) = @_;
return ($value > 0.0) ?
"<b>$value%</b>" : "$value%";
},
"\%MEM" => sub {
my($value) = @_;
return "$value%";
},
"VSZ" => sub {
my($value) = @_;
$value =~ s/(?<=\d)(?=(\d\d\d)+$)/,/g;
return "$value kb";
},
"RSS" => sub {
my($value) = @_;
$value =~ s/(?<=\d)(?=(\d\d\d)+$)/,/g;
return "$value kb";
}
);
push @return, <<EOF;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<title>$ENV{SERVER_NAME}: $command</title>
</head>
<body>
<table border="1">
<tr>
EOF
foreach(@header) {
push @return, " <th>$_</th>\n";
}
push @return, " </tr>\n";
foreach(@lines) {
my @field = split(/\s+/, $_, $#header+1);
push @return, " <tr>\n";
my $f=0;
foreach(@field) {
$_ = &{$format{$header[$f]}}($_)
if(defined $format{$header[$f]});
push @return, " <td>$_</td>\n";
$f++;
}
push @return, " </tr>\n";
}
push @return, <<EOF;
</table>
</body>
</html>
EOF
return @return;
},
);
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.