我们公司管理着超过100台服务器,我们希望每天使用http向这些服务器“询问”一到两次基本使用信息。使用信息可以很容易地找到与perl cgi脚本,我们希望有一个http接口,以简化脚本的创建和测试。让apache,甚至是nginx+fcgiwrap,每天为一两个请求提供服务似乎有点夸张。我们正在考虑使用openbsd-inetd (它已经安装在所有服务器上)来启动一个web服务器,该服务器可以轻松地将请求传递给perl cgi脚本并退出。有什么好的替代方案可以做到这一点?
我已经设法让这个perlscript.pl
工作了,但我不确定它是否是正确的方法。
#!/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'
);
其中,inetd.conf
具有
8901 stream tcp nowait root /home/perl/scriptname.pl
发布于 2014-02-15 03:30:50
如果您不想向这些机器添加守护程序,那么您必须使用现有的守护程序。我假设已经安装了SSH?我会用这句话。可能是一个比使用HTTP更安全的解决方案。
https://stackoverflow.com/questions/21784902
复制相似问题