package test::openssh;
use strict;
use warnings;
use constant MP2 => (($ENV{MOD_PERL_API_VERSION} || 0) >= 2
or eval "require Apache2::ServerUtil; Apache2::ServerUtil::server_root ()");
BEGIN {
if (MP2) {
require Apache2::Const;
require Apache2::RequestRec;
require Apache2::RequestUtil;
Apache2::Const->import(qw(OK));
} else {
require Apache::Constants;
Apache::Constants->import(qw(OK));
}
}
use Net::OpenSSH;
use File::Temp qw(tempdir);
# Please change the following two lines:
use constant SSH_HOST => 'user@host';
use constant SSH_PRIVATE_KEY => "/path/to/private/key/id_dsa";
sub handler ($$) {
my($class, $r) = @_;
my $ctl_dir = tempdir(CLEANUP => 1, TMPDIR => 1) or die $!;
my $ssh = Net::OpenSSH->new(SSH_HOST,
master_opts => ["-vvv", -i => SSH_PRIVATE_KEY, -o => "stricthostkeychecking=no"],
ctl_dir => $ctl_dir,
strict_mode => 0,
);
die $ssh->error if $ssh->error;
my $date = $ssh->capture("date");
$r->send_http_header;
$r->print("hello, the date at " . $ssh->get_host . " is $date\n");
OK;
}
1;
__END__
####
#use lib "/tmp/lib"; # if necessary
PerlModule test::openssh
SetHandler perl-script
PerlHandler test::openssh->handler
####
[Wed Mar 24 15:31:29 2010] [error] unable to establish master SSH connection: Unknown error at .../test/openssh.pm line 33
####
[Wed Mar 24 14:59:55 2010] [error] [client 127.0.0.1] child process STDIN is not a real system file handle at /tmp/lib/test/openssh.pm line 29\n\t(in cleanup) child process STDIN is not a real system file handle at -e line 0\n