Greetings,
This might give you an outline to get started. It's a fairly nasty and rapidly punched in piece of code, so improvements are certainly required.
#!/usr/bin/perl -wT
use strict;
use CGI 'header';
my $data = `sudo printstatus`;
open(LOG, '>> some.log.file') || die "Badness: $!\n";
print LOG $data, "\n\n", '=' x 75, "\n\n";
close(LOG);
print header;
print "<HTML><HEAD><TITLE>sudo printstatus</TITLE></HEAD>\n";
print "<H2>sudo printstatus</H2>\n<PRE>";
open(READLOG, 'some.log.file') || die "Badness: $!\n";
while (<READLOG>) {
s/</</g;
s/>/>/g;
print;
}
close(READLOG);
print "</PRE></BODY></HTML>\n";
Of course, you can also parse the output of your command and put it into a nice looking table or something. Also, this only logs stuff when the user actually accesses the CGI. Also, it appends the new data to the end of the log rather than the beginning. That might be annoying for longer files.
-gryphon
code('Perl') || die; |