/[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

Contents of /lib/PXElator/ssh.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 348 - (show annotations)
Sat Aug 29 18:07:49 2009 UTC (14 years, 8 months ago) by dpavlin
File size: 1174 byte(s)
execute shell commands over ssh for OpenVZ

1 package ssh;
2
3 use Net::OpenSSH;
4 use English;
5 use Data::Dump qw/dump/;
6
7 my $id = 2;
8
9 sub ethernet_bridge_to {
10 my $host = shift;
11
12 die "you need to run this as root\n" unless $UID == 0;
13
14 warn "# reset local IP address";
15 system "ifconfig virtual 172.16.10.$id";
16
17 warn "# connect to $host";
18 my $ssh = Net::OpenSSH->new( $host,
19 master_opts => [ -w => "$id:$id", -o => 'Tunnel=ethernet' ],
20 );
21
22 foreach my $command ( "ifconfig tap$id up", "brctl addif virtual tap$id" ) {
23 warn "# $command";
24 system $command;
25 $ssh->system( $command ) or die "$command ", $ssh->error;
26 }
27
28 warn "press enter to close tunnel to $host from $id";
29 <STDIN>;
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;

  ViewVC Help
Powered by ViewVC 1.1.26