我正在编写一个使用perl通过SSH远程执行命令的脚本。当a) SSH客户端无法连接b) SSH客户端能够连接,但远程命令需要更长时间(例如>5分钟)执行时,可能会发生超时
对于(a),ssh客户端中提供了一个选项。对于(b),我找不到任何东西。感谢您的任何意见
发布于 2012-03-30 17:21:31
my $ssh = Net::OpenSSH->new($host, kill_ssh_on_timeout => 1, timeout => 5);
my $output = $ssh->capture({tty => 1, timeout => 300}, $cmd);不过,请阅读模块文档中有关超时的the entry。
发布于 2012-03-29 19:58:34
man ssh_config建议ServerAliveInterval就是你要搜索的内容:
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.发布于 2012-03-29 21:07:10
你正在寻找的是一个超时唤醒功能?如果您习惯于发出信号,请尝试使用POSIX::alarm()。或者检查Perl模块IPC::Run。
https://stackoverflow.com/questions/9924784
复制相似问题