'net/ssh' error /usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.23/lib/net/ssh/transport/session.rb:65:in `i

Hi,

I am trying to do ssh to multiple servers and get their versions using
ruby Net::SSH

When I assign a host name to a variable and used in Net::SSH it works
fine

server=“test.server.com
Net::SSH.start(server, USER, :password=>PASSWORD) do |ssh|
result=ssh.exec!(‘hostname’)
puts result
end

Whereas I put the servername in file read it in to a array, use each
method for individual servers

SERVER_LIST.each do |server|

            Net::SSH.start(server, USER, :password=>PASSWORD) do

|ssh|
host_name=ssh.exec!(‘hostname’)
puts result
end

It fails with the error,

/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.23/lib/net/ssh/transport/session.rb:65:in
initialize': newline at the end of hostname (SocketError) from /usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.23/lib/net/ssh/transport/session.rb:65:in open’
from
/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.23/lib/net/ssh/transport/session.rb:65:in
initialize' from /usr/lib/ruby/1.8/timeout.rb:48:in timeout’
from /usr/lib/ruby/1.8/timeout.rb:76:in timeout' from /usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.23/lib/net/ssh/transport/session.rb:65:in initialize’
from
/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.23/lib/net/ssh.rb:179:in new' from /usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.23/lib/net/ssh.rb:179:in start’

Am i missing something here?

Regards,

I am so sorry,

It was the new line character that was creating problems.

Fixed it

SERVER_LIST.each do |server|

            SERVER=server.chomp
            Net::SSH.start(SERVER, USER, :password=>PASSWORD) do

|ssh|

Sorry I am a beginner

Regards,

Athreya

Athreya Vc wrote in post #970247:

Hi,

I am trying to do ssh to multiple servers and get their versions using
ruby Net::SSH

When I assign a host name to a variable and used in Net::SSH it works
fine

server=“test.server.com
Net::SSH.start(server, USER, :password=>PASSWORD) do |ssh|
result=ssh.exec!(‘hostname’)
puts result
end

Whereas I put the servername in file read it in to a array, use each
method for individual servers

SERVER_LIST.each do |server|

            Net::SSH.start(server, USER, :password=>PASSWORD) do

|ssh|
host_name=ssh.exec!(‘hostname’)
puts result
end

It fails with the error,

/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.23/lib/net/ssh/transport/session.rb:65:in

`initialize’: newline at the end of
hostname (SocketError)
from

/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.23/lib/net/ssh/transport/session.rb:65:in

`open’
from

/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.23/lib/net/ssh/transport/session.rb:65:in

initialize' from /usr/lib/ruby/1.8/timeout.rb:48:in timeout’
from /usr/lib/ruby/1.8/timeout.rb:76:in `timeout’
from

/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.23/lib/net/ssh/transport/session.rb:65:in

initialize' from /usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.23/lib/net/ssh.rb:179:in new’
from
/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.23/lib/net/ssh.rb:179:in `start’

Am i missing something here?

Regards,

On Thu, Dec 23, 2010 at 4:00 AM, Athreya Vc [email protected]
wrote:

I am so sorry,

It was the new line character that was creating problems.

Fixed it

No need to apologize. Welcome to the community. :slight_smile:

SERVER_LIST.each do |server|
SERVER=server.chomp
Net::SSH.start(SERVER, USER, :password=>PASSWORD) do

Stylistically, rather than using SERVER as a variable (uppercase
indicates a constant), so I would do something like:

A) s = server.chomp; Net::SSH.start(s, …
B) server = server.chomp; Net::SSH.start(server, …
C) Net::SSH.start(server.chomp, …
D) current_host = server.chomp; …

Yes sir, I did that too.

Immediately it threw an error saying constant can’t be changed.

Thanks for the suggestion.

The script is working great and I am happy.

Regards,

Athreya

unknown wrote in post #970299:

On Thu, Dec 23, 2010 at 4:00 AM, Athreya Vc [email protected]
wrote:

I am so sorry,

It was the new line character that was creating problems.

Fixed it

No need to apologize. Welcome to the community. :slight_smile:

SERVER_LIST.each do |server|
SERVER=server.chomp
Net::SSH.start(SERVER, USER, :password=>PASSWORD) do

Stylistically, rather than using SERVER as a variable (uppercase
indicates a constant), so I would do something like:

A) s = server.chomp; Net::SSH.start(s, …
B) server = server.chomp; Net::SSH.start(server, …
C) Net::SSH.start(server.chomp, …
D) current_host = server.chomp; …