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;
issh('user@hostname', $command);
+ ssh_cmd('user@hostname', $command);
+
sshopen2('user@hostname', $reader, $writer, $command);
sshopen3('user@hostname', $writer, $reader, $error, $command);
}
}
+=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).
=head1 SEE ALSO
-ssh-keygen(1), ssh(1), L<IPC::Open2>, L<IPC::Open3>
+ssh-keygen(1), ssh(1), L<IO::File>, L<IPC::Open2>, L<IPC::Open3>
=cut