我希望能够使用 ruby net-ssh gem 来更改 Juniper M10i 路由器。但是,发送“配置”后,我无法发送任何配置命令。
例如,通过 ssh 登录到路由器后,我想发出以下三个命令:
configure
show system
exit
使用 net-ssh 库,我尝试了以下操作但没有成功:
# 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!
那么如何在“configure”之后正确传递“show system”命令呢?
解决了:
我偶然发现了以下帖子:https ://stackoverflow.com/a/6807178/152852