/[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 283 by dpavlin, Mon Aug 24 18:07:19 2009 UTC revision 348 by dpavlin, Sat Aug 29 18:07:49 2009 UTC
# Line 1  Line 1 
1  package ssh;  package ssh;
2    
3  use Net::OpenSSH;  use Net::OpenSSH;
4    use English;
5    use Data::Dump qw/dump/;
6    
7  my $id = 2;  my $id = 2;
8    
9  sub ethernet_bridge_to {  sub ethernet_bridge_to {
10          my $host = shift;          my $host = shift;
11    
12            die "you need to run this as root\n" unless $UID == 0;
13    
14          warn "# reset local IP address";          warn "# reset local IP address";
15          system "ifconfig virtual 172.16.10.$id";          system "ifconfig virtual 172.16.10.$id";
16    
# Line 26  sub ethernet_bridge_to { Line 30  sub ethernet_bridge_to {
30    
31  }  }
32    
33    sub shell {
34            my $host = shift;
35    
36            my $ssh = Net::OpenSSH->new( $host );
37    
38            my $html;
39    
40            foreach my $command ( @_ ) {
41                    warn "root\@$host:# $command\n";
42                    my ($out,$err) = $ssh->capture2( $command ) or die "$command ", $ssh->error;
43                    warn "$out\n$err";
44    
45                    $html .= qq|<tt style="color: grey">root\@$host:# <b>$command</b></tt><pre>$out</pre>|;
46                    $html .= qq|<pre style="color: red">$err</pre>| if $err;
47            }
48    
49            return $html;
50    }
51    
52    sub copy_id {
53            my $host = shift;
54            system 'sudo ssh-copy-id -i /root/.ssh/id_rsa.pub root@' . $host;
55    }
56    
57  1;  1;

Legend:
Removed from v.283  
changed lines
  Added in v.348

  ViewVC Help
Powered by ViewVC 1.1.26