oops, bad email addresses
[Net-SSH.git] / SSH.pm
1 package Net::SSH;
2
3 use strict;
4 use vars qw($VERSION @ISA @EXPORT_OK $ssh);
5 use Exporter;
6 use IPC::Open2;
7 use IPC::Open3;
8
9 @ISA = qw(Exporter);
10 @EXPORT_OK = qw( ssh issh sshopen2 sshopen3 );
11 $VERSION = '0.01';
12
13 $ssh = "ssh";
14
15 =head1 NAME
16
17 Net::SSH - Perl extension for secure shell
18
19 =head1 SYNOPSIS
20
21   use Net::SSH qw(ssh issh sshopen2 sshopen3);
22
23   ssh('user@hostname', $command);
24
25   issh('user@hostname', $command);
26
27   sshopen2('user@hostname', $reader, $writer, $command);
28
29   sshopen3('user@hostname', $reader, $writer, $error, $command);
30
31 =head1 DESCRIPTION
32
33 Simple wrappers around ssh commands.
34
35 =head1 SUBROUTINES
36
37 =over 4
38
39 =item ssh [USER@]HOST, COMMAND [, ARGS ... ]
40
41 Calls ssh in batch mode.
42
43 =cut
44
45 sub ssh {
46   my($host, @command) = @_;
47   my @cmd = ($ssh, '-o', 'BatchMode yes', $host, @command);
48   system(@cmd);
49 }
50
51 =item issh [USER@]HOST, COMMAND [, ARGS ... ]
52
53 Prints the ssh command to be executed, waits for the user to confirm, and
54 (optionally) executes the command.
55
56 =cut
57
58 sub issh {
59   my($host, @command) = @_;
60   my @cmd = ($ssh, $host, @command);
61   print join(' ', @cmd), "\n";
62   if ( &_yesno ) {
63     system(@cmd);
64   }
65 }
66
67 =item sshopen2 [USER@]HOST, READER, WRITER, COMMAND [, ARGS ... ]
68
69 Connects the supplied filehandles to the ssh process (in batch mode).
70
71 =cut
72
73 sub sshopen2 {
74   my($host, $reader, $writer, @command) = @_;
75   open2($reader, $writer, $ssh, '-o', 'Batchmode yes', $host, @command);
76 }
77
78 =item sshopen3 HOST, WRITER, READER, ERROR, COMMAND [, ARGS ... ]
79
80 Connects the supplied filehandles to the ssh process (in batch mode).
81
82 =cut
83
84 sub sshopen3 {
85   my($host, $writer, $reader, $error, @command) = @_;
86   open3($writer, $reader, $error, $ssh, '-o', 'Batchmode yes', $host, @command);
87 }
88
89 sub _yesno {
90   print "Proceed [y/N]:";
91   my $x = scalar(<STDIN>);
92   $x =~ /^y/i;
93 }
94
95 =back
96
97 =head1 AUTHOR
98
99 Ivan Kohler <ivan-netssh_pod@420.am>
100
101 =head1 BUGS
102
103 Not OO.
104
105 Look at IPC::Session (also fsh)
106
107 =head1 SEE ALSO
108
109 ssh(1), L<IPC::Open2>, L<IPC::Open3>
110
111 =cut
112
113 1;
114