From b36296a20bb4cd814949c6b92ee46851fd78906d Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 9 Oct 2000 16:28:49 +0000 Subject: [PATCH 1/1] initial import --- Changes | 5 +++ MANIFEST | 7 ++++ MANIFEST.SKIP | 1 + Makefile.PL | 7 ++++ README | 35 ++++++++++++++++++ SSH.pm | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test.pl | 20 +++++++++++ 7 files changed, 189 insertions(+) create mode 100644 Changes create mode 100644 MANIFEST create mode 100644 MANIFEST.SKIP create mode 100644 Makefile.PL create mode 100644 README create mode 100644 SSH.pm create mode 100644 test.pl diff --git a/Changes b/Changes new file mode 100644 index 0000000..991346d --- /dev/null +++ b/Changes @@ -0,0 +1,5 @@ +Revision history for Perl extension Net::SSH. + +0.01 Thu Aug 17 17:44:21 2000 + - original version; created by h2xs 1.19 + diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..d95fbc8 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,7 @@ +Changes +MANIFEST +MANIFEST.SKIP +Makefile.PL +SSH.pm +test.pl +README diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP new file mode 100644 index 0000000..ae335e7 --- /dev/null +++ b/MANIFEST.SKIP @@ -0,0 +1 @@ +CVS/ diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..e42251f --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,7 @@ +use ExtUtils::MakeMaker; +# See lib/ExtUtils/MakeMaker.pm for details of how to influence +# the contents of the Makefile that is written. +WriteMakefile( + 'NAME' => 'Net::SSH', + 'VERSION_FROM' => 'SSH.pm', # finds $VERSION +); diff --git a/README b/README new file mode 100644 index 0000000..0f4a491 --- /dev/null +++ b/README @@ -0,0 +1,35 @@ +Net::SSH v0.01 + +Copyright (c) 2000 Ivan Kohler. +Copyright (c) 2000 Silicon Interactive Software Design. +Copyright (c) 2000 Freeside Internet Services, LLC +All rights reserved. +This program is free software; you can redistribute it and/or modify it under +the same terms as Perl itself. + +This module implements a Perl interface to ssh. + +To install: + perl Makefile.PL + make + make test # nothing substantial yet + make install + +Documentation will then be available via `man Net:SSH' or `perldoc Net::SSH' + +Anonymous CVS access is available: + $ export CVSROOT=":pserver:anonymous@cleanwhisker.420.am:/home/cvs/cvsroot" + $ cvs login + (Logging in to anonymous@pouncequick.cleanwhisker.420.am) + CVS password: anonymous + $ cvs checkout Net-SSH +as well as . + +A mailing list for users and developers is available. Send a blank message to + to subscribe. + +Ivan Kohler +20 4,16 * * * saytime + +$Id: README,v 1.1 2000-10-09 16:28:49 ivan Exp $ + diff --git a/SSH.pm b/SSH.pm new file mode 100644 index 0000000..81ee35b --- /dev/null +++ b/SSH.pm @@ -0,0 +1,114 @@ +package Net::SSH; + +use strict; +use vars qw($VERSION @ISA @EXPORT_OK $ssh); +use Exporter; +use IPC::Open2; +use IPC::Open3; + +@ISA = qw(Exporter); +@EXPORT_OK = qw( ssh issh sshopen2 sshopen3 ); +$VERSION = '0.01'; + +$ssh = "ssh"; + +=head1 NAME + +Net::SSH - Perl extension for secure shell + +=head1 SYNOPSIS + + use Net::SSH qw(ssh issh sshopen2 sshopen3); + + ssh('user@hostname', $command); + + issh('user@hostname', $command); + + sshopen2('user@hostname', $reader, $writer, $command); + + sshopen3('user@hostname', $reader, $writer, $error, $command); + +=head1 DESCRIPTION + +Simple wrappers around ssh commands. + +=head1 SUBROUTINES + +=over 4 + +=item ssh [USER@]HOST, COMMAND [, ARGS ... ] + +Calls ssh in batch mode. + +=cut + +sub ssh { + my($host, @command) = @_; + my @cmd = ($ssh, '-o', 'BatchMode yes', $host, @command); + system(@cmd); +} + +=item issh [USER@]HOST, COMMAND [, ARGS ... ] + +Prints the ssh command to be executed, waits for the user to confirm, and +(optionally) executes the command. + +=cut + +sub issh { + my($host, @command) = @_; + my @cmd = ($ssh, $host, @command); + print join(' ', @cmd), "\n"; + if ( &_yesno ) { + system(@cmd); + } +} + +=item sshopen2 [USER@]HOST, READER, WRITER, COMMAND [, ARGS ... ] + +Connects the supplied filehandles to the ssh process (in batch mode). + +=cut + +sub sshopen2 { + my($host, $reader, $writer, @command) = @_; + open2($reader, $writer, $ssh, '-o', 'Batchmode yes', $host, @command); +} + +=item sshopen3 HOST, WRITER, READER, ERROR, COMMAND [, ARGS ... ] + +Connects the supplied filehandles to the ssh process (in batch mode). + +=cut + +sub sshopen3 { + my($host, $writer, $reader, $error, @command) = @_; + open3($writer, $reader, $error, $ssh, '-o', 'Batchmode yes', $host, @command); +} + +sub _yesno { + print "Proceed [y/N]:"; + my $x = scalar(); + $x =~ /^y/i; +} + +=back + +=head1 AUTHOR + +Ivan Kohler + +=head1 BUGS + +Not OO. + +Look at IPC::Session? + +=head1 SEE ALSO + +ssh(1), L, L + +=cut + +1; + diff --git a/test.pl b/test.pl new file mode 100644 index 0000000..b3ad4e1 --- /dev/null +++ b/test.pl @@ -0,0 +1,20 @@ +# Before `make install' is performed this script should be runnable with +# `make test'. After `make install' it should work as `perl test.pl' + +######################### We start with some black magic to print on failure. + +# Change 1..1 below to 1..last_test_to_print . +# (It may become useful if the test is moved to ./t subdirectory.) + +BEGIN { $| = 1; print "1..1\n"; } +END {print "not ok 1\n" unless $loaded;} +use Net::SSH; +$loaded = 1; +print "ok 1\n"; + +######################### End of black magic. + +# Insert your test code below (better if it prints "ok 13" +# (correspondingly "not ok 13") depending on the success of chunk 13 +# of the test code): + -- 2.11.0