Question

Our company manages over one hundred servers and we would like to "ask" these servers for basic usage info once or twice a day using http. The usage info can be easily found with a perl cgi script and we would like to have an http interface to ease the creation of scripts and testing them. It seems an overkill to have apache, or even nginx+fcgiwrap, to serve one or two requests per day. We were thinking of using openbsd-inetd (which is already installed in all the servers) to launch a web server that could easily pass the request to the perl cgi script and the quit. What are good alternatives to do this?

I've managed to get this perlscript.pl to work, but I'm not sure if it is the right approach.

#!/usr/bin/perl                                                                                                                                                                                           

use strict;
use warnings;

{
    package BackupWebServer;

    use HTTP::Server::Simple::CGI;
    use base qw(HTTP::Server::Simple::CGI);


    my %dispatch = (
        '/hello' => \&resp_hello
        );


    sub net_server { 'Net::Server::INET' }

    sub handle_request {

        my $self = shift;
        my $cgi  = shift;

        my $path = $cgi->path_info();
        my $handler = $dispatch{$path};

        if (ref($handler) eq "CODE") {
            print "HTTP/1.0 200 OK\r\n";
            $handler->($cgi);
        } else {
            print "HTTP/1.0 404 Not found\r\n";
            print $cgi->header,
            $cgi->start_html('Not found'),
            $cgi->h1('Not found'),
            $cgi->end_html;
        }

    }


    sub resp_hello {

        my $cgi  = shift;   # CGI.pm object                                                                                                                                                               
        return if !ref $cgi;

        my $who = $cgi->param('name');

        print $cgi->header,
        $cgi->start_html("Hello"),
        $cgi->h1("Hello $who!"),
        $cgi->end_html;

    }


}

BackupWebServer->new()->run(
    log_file => 'Sys::Syslog',
    user => 'root',
    group => 'root'
    );

With an inetd.conf having

8901    stream  tcp     nowait  root    /home/perl/scriptname.pl

No correct solution

OTHER TIPS

If you don't want to add a deamon to those machines, then you'll have to use an existing one. I presume SSH is installed? I'd use that. Possibly a more secure solution that using HTTP anyway.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top