From 51d21ed6c0bf29dbf44046ab1ea66c350f96ebb9 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sun, 26 Jan 2014 20:46:22 +0100 Subject: [PATCH] utilisation de Net::SSH1 --- app/zone/edit.pm | 20 +++++++++++--------- t/ssh1.pl | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 t/ssh1.pl diff --git a/app/zone/edit.pm b/app/zone/edit.pm index 0d619d0..188efb8 100644 --- a/app/zone/edit.pm +++ b/app/zone/edit.pm @@ -3,7 +3,7 @@ use Data::Dump "dump"; use DNS::ZoneParse; use File::Copy; use Net::SCP; -use Net::SSH2; +use Net::SSH q; use v5.14; use lib '../../'; @@ -165,15 +165,17 @@ sub del { $rndc->delzone($self->zdir, $self->zname); $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; - $chan->exec( "rm $file" ); - $ssh->disconnect(); + my $host = $self->host; + my $user = $self->user; + my $cmd = "rm $file"; + + sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!"; + + close(READER); + close(WRITER); + + 1; } diff --git a/t/ssh1.pl b/t/ssh1.pl new file mode 100644 index 0000000..b1d412c --- /dev/null +++ b/t/ssh1.pl @@ -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; + +my $host = "pizza"; +my $user = "karchnu"; +my $cmd = "ls /"; + +sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!"; + +while () { + chomp(); + print "$_\n"; +} + +close(READER); +close(WRITER); +