3
0

utilisation de Net::SSH1

This commit is contained in:
Philippe Pittoli 2014-01-26 20:46:22 +01:00
parent 59cf727e28
commit 51d21ed6c0
2 changed files with 35 additions and 9 deletions

View File

@ -3,7 +3,7 @@ use Data::Dump "dump";
use DNS::ZoneParse; use DNS::ZoneParse;
use File::Copy; use File::Copy;
use Net::SCP; use Net::SCP;
use Net::SSH2; use Net::SSH q<sshopen2>;
use v5.14; use v5.14;
use lib '../../'; use lib '../../';
@ -165,15 +165,17 @@ sub del {
$rndc->delzone($self->zdir, $self->zname); $rndc->delzone($self->zdir, $self->zname);
$rndc->reconfig(); $rndc->reconfig();
my $ssh = Net::SSH2->new();
$ssh->connect($self->host);
$ssh->auth( username => $self->user);
my $chan = $ssh->channel();
my $file = $self->zdir.'/'.$self->zname; my $file = $self->zdir.'/'.$self->zname;
$chan->exec( "rm $file" ); my $host = $self->host;
$ssh->disconnect(); my $user = $self->user;
my $cmd = "rm $file";
sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!";
close(READER);
close(WRITER);
1; 1;
} }

24
t/ssh1.pl Normal file
View File

@ -0,0 +1,24 @@
#!/usr/bin/perl -w
use strict;
use warnings;
use v5.14;
use autodie;
use Modern::Perl;
use Data::Dump qw( dump );
use DNS::ZoneParse;
use Net::SSH q<sshopen2>;
my $host = "pizza";
my $user = "karchnu";
my $cmd = "ls /";
sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!";
while (<READER>) {
chomp();
print "$_\n";
}
close(READER);
close(WRITER);