From: Miroslaw Niegowski Date: 2013-03-01T06:47:55+09:00 Subject: Re: telnet - how to loop through commands listed in a file --bcaec554d23282d5de04d6cfccb2 Content-Type: text/plain; charset=ISO-8859-2 Content-Transfer-Encoding: quoted-printable Hi, I believe you have an error in your for loop. why don't you try this for example: net =3D Net::Telnet::new("Host" =3D> "#{$host}", "TIMEOUT" =3D> 10, "Prompt= " =3D> /[$%#>] \z/ telnet.login("admin", "password") { |c| print c } File.open ("CMDs.txt").each { | line | telnet.cmd (line.gsub("\"","")) { ...} } I hope you get the idea. And if you can use ssh to manage your network switch. 28-02-2013 22:26, "Bob Ford" napisa=B3(a): > Let me first explain what I'm trying to do. I have written a very > simplistic ruby telnet script. It logs in and can send one command I > give from the command line. > > What I need, or want, to do is have a file which contains multiple > commands I would like to have executed on the switch I am connecting to > via telnet. > > The script and a sample of the file are attached. > > I currently have not removed the command line argument for passing in > the telnet command but it is not used so using a -c "nothing" gets me > past that. If and when I can get the source file working I will change > that for naming the file. > > I get a failure in the for loop "C:Ruby Scripts/Telnet.rb:54:in > `
': undefined method `each' for # > (NoMethodError) > > If I enter a telnet.cmd line for each command it works but then it > limits the flexibility of being able to have multiple files with > different commands. > > Thank you for any assistance. It would be greatly appreciated. > > Attachments: > http://www.ruby-forum.com/attachment/8185/TelnetCmds.rb > http://www.ruby-forum.com/attachment/8186/CMDs.txt > > > -- > Posted via http://www.ruby-forum.com/. > > --bcaec554d23282d5de04d6cfccb2 Content-Type: text/html; charset=ISO-8859-2 Content-Transfer-Encoding: quoted-printable

Hi, I believe you have an error in your for loop. why don't you try = this for example:
net =3D Net::Telnet::new("Host" =3D> "#{$host}", &qu= ot;TIMEOUT" =3D> 10, "Prompt" =3D> /[$%#>] \z/
telnet.login("admin", "password") { |c| print c }
File.open ("CMDs.txt").each
{ | line |
telnet.cmd (line.gsub("\"","")) { ...}
}

I hope you get the idea.
And if you can use ssh to manage your network switch.

28-02-2013 22:26, "Bob Ford" <lists@ruby-forum.com> napisa=B3(a= ):
Let me first explain what I'm trying to do. =A0I have written a very simplistic ruby telnet script. =A0It logs in and can send one command I
give from the command line.

What I need, or want, to do is have a file which contains multiple
commands I would like to have executed on the switch I am connecting to
via telnet.

The script and a sample of the file are attached.

I currently have not removed the command line argument for passing in
the telnet command but it is not used so using a -c "nothing" get= s me
past that. =A0If and when I can get the source file working I will change that for naming the file.

I get a failure in the for loop "C:Ruby Scripts/Telnet.rb:54:in
`<main>': undefined method `each' for #<String:0x2949e58&g= t;
(NoMethodError)

If I enter a telnet.cmd line for each command it works but then it
limits the flexibility of being able to have multiple files with
different commands.

Thank you for any assistance. =A0It would be greatly appreciated.

Attachments:
http://www.ruby-forum.com/attachment/8185/TelnetCmds.rb
http://www.ruby-forum.com/attachment/8186/CMDs.txt


--
Posted via http://= www.ruby-forum.com/.

--bcaec554d23282d5de04d6cfccb2--