Help with net-ssh 2.0

Discussion in 'Ruby' started by Jay Rajaram, May 7, 2008.

  1. Jay Rajaram

    Jay Rajaram Guest

    Hi..,

    I am trying to use net-ssh for executing unix level commands using
    net-ssh across many servers. I am looking for an example that would
    allow me to use net-ssh similar to EXPECT.

    As a first step I tried the following:
    ___________________________________________________________________________

    #!/usr/bin/ruby

    require 'rubygems'
    require 'net/ssh'

    Net::SSH.start('myhostname', 'username', :password => "password") do
    |ssh|

    #I need to sudo further into a different account
    #How do I open a channel with PTY for this as the
    #sudo fails without a proper terminal.

    ssh.open_channel do |channel|

    channel.on_data { |ch, data| puts "stdout: #{data}" }
    channel.on_extended_data { |ch, type, data| puts "stderr:
    #{data}" }

    #The following command produces output
    channel.exec "hostname"

    #The following doesnot produce any output
    channel.exec "uptime"

    end

    #Not sure what is the purpose of the next statement
    ssh.loop

    end

    ___________________________________________________________________________


    Would anyone please show me an example script of how to open a PTY
    channel to make the sudo succeed and subsequently send commands and
    receive output from stdout and stderror.

    Thanks
    Jay
    --
    Posted via http://www.ruby-forum.com/.
    Jay Rajaram, May 7, 2008
    #1
    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:
    387
    loial
    Feb 3, 2009
  2. loial
    Replies:
    0
    Views:
    391
    loial
    Feb 10, 2009
  3. Tench Johnson
    Replies:
    1
    Views:
    280
    Biff Tannen
    Apr 23, 2010
  4. salamond

    net/ssh in ruby. ssh.exec fails

    salamond, Feb 17, 2011, in forum: Ruby
    Replies:
    0
    Views:
    228
    salamond
    Feb 17, 2011
  5. Replies:
    0
    Views:
    82
Loading...

Share This Page