我希望能够使用对Juniper M10i路由器进行更改。但是,在发送“配置”之后,我无法发送任何配置命令。
例如,在通过ssh登录到路由器之后,我想发出以下三个命令:
configure
show system
exit使用net库,我尝试了以下操作,但没有成功:
# net-ssh (2.3.0)
require 'net/ssh'
session = Net::SSH.start(host, user, :password => password)
session.exec!('term length 0')
session.exec!('term width 0')
channel = session.open_channel do |ch|
puts "Channel open."
ch.on_close do |ch|
puts "Channel is closing!"
end
ch.on_data do |ch, data|
puts "Data #{data}!!!!!!!!!!"
end
ch.exec "configure" do |ch, success|
puts "FAIL: configure" unless success
end
ch.exec "show system" do |ch, success|
puts "FAIL: show system" unless success
end
ch.exec "exit" do |ch, success|
puts "FAIL: exit" unless success
end
end
session.loop执行时,我得到以下输出:
Channel open.
FAIL: show system
FAIL: exit
Data Entering configuration mode
!!!!!!!!!!
Channel is closing!那么,如何在“配置”之后正确地传递"show system“命令呢?
解决:
我无意中发现了以下帖子:https://stackoverflow.com/a/6807178/152852
发布于 2012-04-26 19:41:02
基于post,https://stackoverflow.com/a/6807178/152852,额外的创业板"net-ssh-telnet“提供了我正在寻找的确切行为。
require 'net/ssh'
require 'net/ssh/telnet'
session = Net::SSH.start(host, user, :password => password)
t = Net::SSH::Telnet.new("Session" => session, "Prompt" => prompt)
puts t.cmd 'configure'
puts t.cmd 'show | compare'
puts t.cmd 'exit'
puts t.cmd 'exit'https://stackoverflow.com/questions/10327141
复制相似问题