I'd like to be able to use the ruby net-ssh gem to make changes to a Juniper M10i router. However, after sending "configure", I am unable to send any configuration commands.
For example, after logging in to the router via ssh, I'd like to issue the following three commands:
configure
show system
exit
Using the net-ssh library, i've tried the following without success:
# 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
Upon execution I get the following output:
Channel open.
FAIL: show system
FAIL: exit
Data Entering configuration mode
!!!!!!!!!!
Channel is closing!
So how do I correctly pass the "show system" command after "configure"?
SOLVED:
I stumbled across the following post: https://stackoverflow.com/a/6807178/152852