/[pxelator]/lib/PXElator/ssh.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/PXElator/ssh.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 350 by dpavlin, Sat Aug 29 18:07:49 2009 UTC revision 351 by dpavlin, Sat Aug 29 21:10:21 2009 UTC
# Line 1  Line 1 
1  package ssh;  package ssh;
2    
3    use warnings;
4    use strict;
5    
6  use Net::OpenSSH;  use Net::OpenSSH;
7  use English;  use English;
8  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
9    use client;
10    use CouchDB;
11    
12  my $id = 2;  my $id = 2;
13    
# Line 31  sub ethernet_bridge_to { Line 36  sub ethernet_bridge_to {
36  }  }
37    
38  sub shell {  sub shell {
39          my $host = shift;          my $ip = shift;
40    
41          my $ssh = Net::OpenSSH->new( $host );          my $ssh = Net::OpenSSH->new( $ip );
42    
43          my $html;          my $html;
44            my @shell;
45    
46          foreach my $command ( @_ ) {          foreach my $command ( @_ ) {
47                  warn "root\@$host:# $command\n";                  warn "root\@$ip:# $command\n";
48                  my ($out,$err) = $ssh->capture2( $command ) or die "$command ", $ssh->error;                  my ($out,$err) = $ssh->capture2( $command ) or die "$command ", $ssh->error;
49                  warn "$out\n$err";                  warn "$out\n$err";
50    
51                  $html .= qq|<tt style="color: grey">root\@$host:# <b>$command</b></tt><pre>$out</pre>|;                  CouchDB::audit( $ip, $command, { ip => $ip, command => $command, out => $out, err => $err } );
52    
53                    $html .= qq|<tt style="color: grey">root\@$ip:# <b>$command</b></tt><pre>$out</pre>|;
54                  $html .= qq|<pre style="color: red">$err</pre>| if $err;                  $html .= qq|<pre style="color: red">$err</pre>| if $err;
55          }          }
56    
57          return $html;          return $html;
58  }  }
59    
60    my $id_pub = '/root/.ssh/id_rsa.pub';
61    
62  sub copy_id {  sub copy_id {
63          my $host = shift;          my $ip = shift;
64          system 'sudo ssh-copy-id -i /root/.ssh/id_rsa.pub root@' . $host;          my $ssh = client::ip_path( $ip, 'ssh' );
65            return if -l $ssh;
66            my $cmd = "sudo ssh-copy-id -i $id_pub root\@$ip";
67            warn "# $cmd\n";
68            system $cmd;
69            symlink $id_pub, $ssh;
70  }  }
71    
72  1;  1;

Legend:
Removed from v.350  
changed lines
  Added in v.351

  ViewVC Help
Powered by ViewVC 1.1.26