'net/ssh' error

A

Athreya Vc

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,
 
A

Athreya Vc

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:
 
B

brabuhr

I am so sorry,

It was the new line character that was creating problems.

Fixed it

No need to apologize. Welcome to the community. :)
SERVER_LIST.each do |server|
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0SERVER=3Dserver.chomp
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Net::SSH.start(SERVER, USER, :password=3D>=
PASSWORD) do

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

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

Athreya Vc

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:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Net::SSH is unable to use my RSA Key 0
net-ssh - execution expired 1
Net::SSH forward local port 0
Net::SSH Problems 0
Problems with net-ssh 0
net/ssh and ruby 1.9.1 3
Error using Net::SSH 6
Problem with net-ssh 0

Members online

No members online now.

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top