If I only have one host in the file the scripts does as intended. As soon as I add another address in the file I get this error. I understand that it does not like the new line character at the end of the first host in the file, how is this problem alleviated? I'm basically looking for the script to run down the hostfile, and for every address or host-name in the file, run the session.
'initialize': newline at the end of hostname
File.read('hostfile').each_line do |hostname|
session = Net::SSH.start(hostname, @username, :password => @password, :encryption => 'aes256-cbc', :host_key => 'ssh-rsa')
cmd_session = Net::SSH::Telnet.new('Session' => session)
cmd_session.cmd("en\r#{@enable}")
cmd_session.cmd('terminal pager 0')
cmd_session.cmd('show threat-detection statistics') { |c| print c }
cmd_session.close
end
session = Net::SSH.start(hostname.strip, @username.....
Should get you going. For further reference see the docs
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.