'net/ssh' error

Discussion in 'Ruby' started by Athreya Vc, Dec 23, 2010.

  1. Athreya Vc

    Athreya Vc Guest

    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,

    --
    Posted via http://www.ruby-forum.com/.
    Athreya Vc, Dec 23, 2010
    #1
    1. Advertising

  2. Athreya Vc

    Athreya Vc Guest

    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,


    --
    Posted via http://www.ruby-forum.com/.
    Athreya Vc, Dec 23, 2010
    #2
    1. Advertising

  3. Athreya Vc

    Guest

    On Thu, Dec 23, 2010 at 4:00 AM, Athreya Vc <> 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, :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; ...
    , Dec 23, 2010
    #3
  4. Athreya Vc

    Athreya Vc Guest

    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 <>
    > 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, :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; ...


    --
    Posted via http://www.ruby-forum.com/.
    Athreya Vc, Dec 23, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. loial
    Replies:
    0
    Views:
    398
    loial
    Feb 3, 2009
  2. loial
    Replies:
    0
    Views:
    403
    loial
    Feb 10, 2009
  3. Tench Johnson
    Replies:
    1
    Views:
    290
    Biff Tannen
    Apr 23, 2010
  4. salamond

    net/ssh in ruby. ssh.exec fails

    salamond, Feb 17, 2011, in forum: Ruby
    Replies:
    0
    Views:
    240
    salamond
    Feb 17, 2011
  5. Replies:
    0
    Views:
    96
Loading...

Share This Page