我正在尝试使用Net :: SSH2 Perl模块检索top命令的输出,但我每次都得到null输出。
代码
use Net::SSH2;
use strict;
my $ssh = Net::SSH2->new();
$ssh->connect('xx.xx.xx.xx');
$ssh->auth(username => 'xxxxxx', password => 'xxxxx');
my $channel = $ssh->channel() or do { print" [LOG ERROR]: Failed to create channel. Exiting ...\n"};
$channel->blocking(0);
$channel->shell() ;
sleep(5);
my $cmd='top -n 1';
print $channel "$cmd\n";
sleep(5);
while(<$channel>)
{
print $_;
}
$channel->close();
$ssh->disconnect();
有人可以帮忙吗。
答案 0 :(得分:-1)
使用'top -b -n 1'
而不是'top -n 1'或'top'