2 |
|
|
3 |
use Net::OpenSSH; |
use Net::OpenSSH; |
4 |
use English; |
use English; |
5 |
|
use Data::Dump qw/dump/; |
6 |
|
|
7 |
my $id = 2; |
my $id = 2; |
8 |
|
|
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; |