我是一位学生工作者。这是我第一次使用perl,但我已经无法解决问题了,所以需要您的帮助!
我正在尝试通过ssh模块将HP Storeonce 3540命令的输出存储到一个变量中,以便提取我想要监视的一些信息:
不确定是否有用,但FYI,输出如下:
system/show> performance
Service Set 1
Storage Usage
Current: xxxxx TB
Maximum: xxxxx TB
Throughput
VTL Read: 0 MB/s
VTL Write: 0 MB/s
NAS Read: 0 MB/s
NAS Write: 0 MB/s
Catalyst Read: 0 MB/s
Catalyst Write: 0 MB/s
Replication
Inbound: 0 MB/s
Outbound: 0 MB/s
Catalyst
Inbound: 0 MB/s
Outbound: 0 MB/s
这是代码:
use Net::SSH::Expect;
use Capture::Tiny ':all';
use Backticks;
( ... )
my $ssh = Net::SSH::Expect->new (
host => $hp_host,
password=> $hp_pwd,
user => $hp_user,
raw_pty => 1,
timeout => 20
);
my $login_output = $ssh->login();
if ($login_output !~ />/)
{
die "Login has failed. Login output was $login_output";
}
$ssh->send("system");
$ssh->waitfor('\>\s*\z', 5) or die "Error #1-system";
$ssh->send("show");
$ssh->waitfor('\>\s*\z', 5) or die "Error #2-show";
在这里,我想要存储“performance”命令的输出。我尝试了很多组合,下面是一些例子:
1-
say '$ssh->send("performance")'->stdout;
得到以下错误:
String found where operator expected at script_hpstoreonce.pl line 67, near "say '$ssh->send("performance")'"
(Do you need to predeclare say?)
syntax error at script_hpstoreonce.pl line xx, near "say '$ssh->send("performance")'"
2-
Backticks->run( '$ssh->send("performance")' );
print $stdout;
没有打印输出。3- 每次在命令前加上
"$ssh-> "
时,都会出现以下错误:例如:
$ssh->Backticks->run( 'send("performance")' );
或者
$string = $ssh->tee('performance');
错误信息:
Can't locate object method "Backticks"/or("Tee")/ via package "Net::SSH::Expect" at script_hpstoreonce.pl line xx.
4-
$test = Backticks->stdout('performance');
print $stdout;
或者
print $test;
错误信息:
Can't locate object method "Backticks" via package "Net::SSH::Expect" at script_hpstoreonce.pl line xx.
5-
我也尝试使用 Capture::Tiny 模块,但同样出现错误:
$stdout = capture { $ssh->send("performance") };
print $stdout;
错误信息:
Can't locate object method "capture" via package "Net::SSH::Expect" at script_hpstoreonce.pl line xx.
但是:
($stdout, $stderr) = capture {$ssh->send("performance")};
print $stdout;
或者
$stdout = capture_stdout{$ssh->exec("performance")};
print $stdout;
或者
my($stdout, $stderr, $exit) = $ssh->send('performance');
print $stdout;
或者
$stdout = $ssh->capture('performance');
print $stdout;
当我运行脚本时,没有打印任何内容。6- 同样的问题也出现在 Tee 中:
$string = tee {$ssh->send("performance")};
print $string;
没有打印输出。
由于即使我使用不同的模块,仍然出现相同的错误,我明白这可能是由于我对语言的了解和经验不足而导致的遗漏,但我似乎无法找到问题出在哪里。问题出现在$ssh->
协议中吗?
谢谢
send
不返回任何内容,所以没有什么可以存储的。你到底想要得到什么,并且你是否阅读了关于该模块的CPAN文档?http://search.cpan.org/~bnegrao/Net-SSH-Expect-1.09/lib/Net/SSH/Expect.pod - scrappedcola