【发布时间】:2021-07-31 21:10:55
【问题描述】:
我正在使用 Ruby Net:SSH 库与远程 PC 建立 ssh 连接,然后执行远程 cmd。 当我开始我的 SSH 连接时,我没有问题,但有时,不是在任何地方,当我使用 exec 时!我有一个错误返回到 stderr,它是“tput: No value for $TERM and no -T specified”。
代码示例:
Net::SSH.start(nodeAddress, nodeLogin, :password => nodePassword, :port => nodePort) do |ssh|
ssh.exec! "cat \"#{sftpSshKey}\"" do |channel, stream, data|
if(stream == :stderr)
return "error tput"
end
end
end
如果有人有想法或已经有这个问题。
猫的例子工作正常,如果我使用这个我得到“tput”错误:
ssh.exec! "test -r \"#{sftpSourceFile}\" && echo \"Read\" || echo \"NRead\"" do |channel, stream, data|
如果我使用这个我没有错误:
ssh.exec! "test -w \"#{nodeDestinationPath}\" && echo \"Write\" || echo \"NWrite\"" do |channel, stream, data|
问候。
【问题讨论】:
-
当您使用 ssh 命令在另一个盒子上执行命令,并且该命令需要从控制台读取某些内容时,您必须提供“-t”开关。您的代码相当于这样做,所以您正在寻找的是 Net::SSH 等效于“-t”开关。
标签: ruby ssh net-ssh remote-execution tput