From a9031ec538ba9b68d1bd9f4538e39b196c05def2 Mon Sep 17 00:00:00 2001 From: jeff Date: Fri, 15 Feb 2002 19:06:20 +0000 Subject: [PATCH] 0.04 Added ssh_cmd --- Changes | 3 +++ SSH.pm | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index 66f3b9c..9db64af 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for Perl extension Net::SSH. +0.04 fri Feb 15 14:05:06 2002 + - added ssh_cmd + 0.03 Wec Oct 24 03:49:06 2001 - current OpenSSH wants s/ /=/ in -o options - more documentation updates diff --git a/SSH.pm b/SSH.pm index e4e0887..990fa20 100644 --- a/SSH.pm +++ b/SSH.pm @@ -3,12 +3,13 @@ package Net::SSH; use strict; use vars qw($VERSION @ISA @EXPORT_OK $ssh $DEBUG); use Exporter; +use IO::File; use IPC::Open2; use IPC::Open3; @ISA = qw(Exporter); -@EXPORT_OK = qw( ssh issh sshopen2 sshopen3 ); -$VERSION = '0.03'; +@EXPORT_OK = qw( ssh issh ssh_cmd sshopen2 sshopen3 ); +$VERSION = '0.04'; $DEBUG = 0; @@ -26,6 +27,8 @@ Net::SSH - Perl extension for secure shell issh('user@hostname', $command); + ssh_cmd('user@hostname', $command); + sshopen2('user@hostname', $reader, $writer, $command); sshopen3('user@hostname', $writer, $reader, $error, $command); @@ -68,6 +71,34 @@ sub issh { } } +=item ssh_cmd [USER@]HOST, COMMAND [, ARGS ... ] + +Calls ssh in batch mode. Dies if data occurs on the error stream. Warns +of data on the output stream. + +=cut + +sub ssh_cmd { + my($host, @command) = @_; + + my $reader = IO::File->new(); + my $writer = IO::File->new(); + my $error = IO::File->new(); + + sshopen3( $host, $reader, $writer, $error, @command ) or die $!; + + local $/ = undef; + my $output_stream = <$writer>; + my $error_stream = <$error>; + if ( length $error_stream ) { + die "[Net:SSH::ssh_cmd] STDERR $error_stream"; + } + if ( length $output_stream ) { + warn "[Net::SSH::ssh_cmd] STDOUT $output_stream"; + } + +} + =item sshopen2 [USER@]HOST, READER, WRITER, COMMAND [, ARGS ... ] Connects the supplied filehandles to the ssh process (in batch mode). @@ -154,7 +185,7 @@ Look at IPC::Session (also fsh) =head1 SEE ALSO -ssh-keygen(1), ssh(1), L, L +ssh-keygen(1), ssh(1), L, L, L =cut -- 2.11.0