Has anyone tried to execute multiple commands in a JUNOS router using ruby with the net/ssh and net/ssh/telnet gems where you have to go into configure mode? It never wants to accept the configure commands and I don't know why.
Here is my code:
def exec_router(host_type, commands)
puts "commands: #{commands}"
output = ""
ssh = Net::SSH.start(HOST_MAP[host_type], QA_USER, :password => QA_USER_PASSWORD)
t = Net::SSH::Telnet.new("Session" => ssh, "Prompt" => /.+@.+>/, "Output_log" => "/tmp/test.outputi")
commands.each { |command| output << t.cmd(command) }
puts output
t.close
ssh.close
end
And here is the output that it produces:
commands: ["configure", "show policy-options prefix-list greautomation-676872"]
configure
^
unknown command.
{master:member0-re0}
[email protected]> show policy-options
^
syntax error, expecting <command>.
[email protected]> show policy-optionsprefix-list ^ syntax error, expecting . [email protected]> show policy-optionsprefix-listgreautomation-676872 ^ syntax error, expecting .
I know my ssh/telnet stuff is working because I can replace the block that iterates through the command array with t.cmd('?') and I get the expected output with no errors.
My Junos version is 15.1F6-S3.8 and I am using ruby 2.3.0.
Thanks in advance
Craig
Have you checked https://github.com/Juniper/net-netconf? It is a Ruby Gem for doing NETCONF based interactions with Junos devices.