首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Perl Net::SSH2和缓冲

Perl Net::SSH2和缓冲
EN

Stack Overflow用户
提问于 2015-01-15 01:42:47
回答 1查看 609关注 0票数 1

有一个使用Net:SSH2模块的小perl脚本

代码语言:javascript
复制
#!/usr/bin/perl
use strict;
use warnings;
use Net::SSH2;

my $ssh2 = Net::SSH2->new();
$ssh2->connect('testhost') or die $!;
if ($ssh2->auth_publickey('admin', 'id_rsa.pub', 'id_rsa')) {
print "Connected\n";
} else {
print "failed";
}
my $sess = $ssh2->channel() or die "Unable to create chan\n";
$sess->blocking(1);
$sess->shell();
print $sess "sudo /root/remote.pl\n";
print "$_\n" while <$sess>;
$sess->send_eof;
$sess->close;

执行此命令后,我有时会看到/root/remote.pl的输出,有时却看不到。我认为问题出在输出缓冲上,但我不知道如何解决这个问题。

EN

回答 1

Stack Overflow用户

发布于 2015-01-15 01:56:28

如果在linux系统上使用此脚本,为什么不使用perl back-tilt来使用linux命令,而不是使用模块呢?

示例:

代码语言:javascript
复制
#!/usr/bin/perl
use strict;
use warnings;

# Command
my $cmd = "ssh login:password@host; sudo /root/remote.pl; exit";

# Execute the command
`$cmd`

PS:如果remote.pl脚本有一些打印,您应该会看到它们。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27949159

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档