From: Bob Ford Date: 2013-03-06T02:55:08+09:00 Subject: Re: telnet - how to loop through commands listed in a file This is all working now. ======================= snippet ======================= telnet = Net::Telnet::new("Host" => "#{$host}", "TIMEOUT" => 10, "Prompt" => /[$%#>] \z/) telnet.login("admin", "password") { |c| print c } File.readlines("#{$file_arg}").each do |line| telnet.cmd(line.gsub("\"", "")) { |c| print c } end telnet.close ======================= snippet end ======================= What I'd like to do now is have the ability to do a nested loop where the script acts on multiple file. I tried many things but the answer eludes me. Here is one attempt: ======================= trial nested loop ======================= filenames = "#{$file_arg}" filenames.each do |filename| File.readlines("filename").each do |line| telnet.cmd(line.gsub("\"", "")) { |c| print c } end end ======================= end trial nested loop ======================= The output is: Ruby Scripts/TelnetCmds.rb:55:in `
': undefined method `each' for "C:\\Scripts\\VLAN_ES7000.txt":String (NoMethodError) Feeling stupid as this should be an easy thing to do. But again, the answer is eluding me. -- Posted via http://www.ruby-forum.com/.