首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果成功建立ssh连接后没有接收到数据,ssh客户端是否可以超时

如果成功建立ssh连接后没有接收到数据,ssh客户端是否可以超时
EN

Stack Overflow用户
提问于 2012-03-29 19:51:58
回答 3查看 2.2K关注 0票数 1

我正在编写一个使用perl通过SSH远程执行命令的脚本。当a) SSH客户端无法连接b) SSH客户端能够连接,但远程命令需要更长时间(例如>5分钟)执行时,可能会发生超时

对于(a),ssh客户端中提供了一个选项。对于(b),我找不到任何东西。感谢您的任何意见

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-03-30 17:21:31

使用Net::OpenSSH

代码语言:javascript
复制
my $ssh = Net::OpenSSH->new($host, kill_ssh_on_timeout => 1, timeout => 5);
my $output = $ssh->capture({tty => 1, timeout => 300}, $cmd);

不过,请阅读模块文档中有关超时的the entry

票数 0
EN

Stack Overflow用户

发布于 2012-03-29 19:58:34

man ssh_config建议ServerAliveInterval就是你要搜索的内容:

代码语言:javascript
复制
ServerAliveInterval
     Sets a timeout interval in seconds after which if no data has been received from the server, ssh(1) will send a message through
     the encrypted channel to request a response from the server.  The default is 0, indicating that these messages will not be sent
     to the server, or 300 if the BatchMode option is set.  This option applies to protocol version 2 only.  ProtocolKeepAlives and
     SetupTimeOut are Debian-specific compatibility aliases for this option.
票数 1
EN

Stack Overflow用户

发布于 2012-03-29 21:07:10

你正在寻找的是一个超时唤醒功能?如果您习惯于发出信号,请尝试使用POSIX::alarm()。或者检查Perl模块IPC::Run。

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

https://stackoverflow.com/questions/9924784

复制
相关文章

相似问题

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