Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > 'net/ssh' error

Reply
Thread Tools

'net/ssh' error

 
 
Athreya Vc
Guest
Posts: n/a
 
      12-23-2010
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, assword=>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, assword=>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,

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

 
Reply With Quote
 
 
 
 
Athreya Vc
Guest
Posts: n/a
 
      12-23-2010
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, assword=>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, assword=>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, assword=>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,


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

 
Reply With Quote
 
 
 
 
brabuhr@gmail.com
Guest
Posts: n/a
 
      12-23-2010
On Thu, Dec 23, 2010 at 4:00 AM, Athreya Vc <(E-Mail Removed)> 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.

> 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, assword=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; ...

 
Reply With Quote
 
Athreya Vc
Guest
Posts: n/a
 
      12-23-2010
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 <(E-Mail Removed)>
> 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.
>
>> SERVER_LIST.each do |server|
>> SERVER=server.chomp
>> Net::SSH.start(SERVER, USER, assword=>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; ...


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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0xffc Thread 0x228 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-30-2006 03:16 PM
Error connecting to SQLExpress 2005 locally (error: 26 - Error Locating Server/Instance Specified) hfk0 ASP .Net 2 03-27-2006 08:43 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 1 03-24-2006 04:20 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-24-2006 02:22 PM
Error 500: ERROR: Cannot forward. Writer or Stream already obtained. Error JavaQueries Java 1 03-01-2005 06:30 PM



Advertisments