这里的学生工作者通过ssh存储输出。这是我第一次使用perl,而且我似乎已经用完了解决方案,所以我需要你的帮助!使用Net :: SSH :: Expect
我尝试在HP的StoreOnce 3540命令的输出中存储通过SSH模块的变量,所以我可以提取一些 信息我想监控:
不知道,如果它是有用的,但FYI输出是这样的:
系统/节目>性能
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";
这里我想存储“性能”命令的输出。 我已经尝试了一堆组合的所以这里有云:
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 - 我还试图用捕捉::微型模块却又:
$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;
不打印干啥g当我运行脚本。
6 - 同样的事情会的发球台:
$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
我试图找回系统/ show/performance命令的输出。我想把这个输出放在一个字符串中,用正则表达式提取一些信息(但现在只是把输出放在一个字符串中,就是我所要求的)。 – Ect0plasme