我有这个脚本来读取设备列表并发送命令。但目前它只读取第一个设备并发送命令,忽略其余部分。我错过了什么?在多个设备上发送命令
#!\usr\bin\Perl\bin\perl
use warnings;
use strict;
use NET::SSH2;
use MIME::Base64;
my $host = "C:/temp/devices.txt"; # input file
my $user = "XXX"; # your account
my $pass = "XXXXXX"; # your password 64 bit mime
my $ssh2 = Net::SSH2->new();
my $result = "C:/temp/result.txt"; # output file
$ssh2->debug(1); # debug on/off
open(List, '<', "$host") or die "$!";
while(<List>) {
chomp $_;
$ssh2->connect("$_") or die "Unable to connect host [email protected] \n";
my $dp=decode_base64("$pass");
$ssh2->auth_password("$user","$dp");
my $chan = $ssh2->channel();
$chan->exec('sh run');
my $buflen =100000;
my $buf = '0' x $buflen;
my $read = $chan->read($buf, $buflen);
warn 'More than ', $buflen, ' characters in listing' if $read >= $buflen;
open OUTPUT, ">", "$result";
print OUTPUT "HOST: $_\n\n";
print OUTPUT "$buf\n";
print OUTPUT "\n\n\n";
print OUTPUT
close (List);
$chan->close();
}
谢谢,这解决了第一个问题。读取第二个设备列表,但现在无法连接到第二个设备出现错误“无法连接到主机” – Daniel 2011-12-14 19:17:06