Ruby - Problems with Expect and Pty

后端 未结 2 1298
心在旅途
心在旅途 2021-02-10 19:05

I\'m trying to write a Ruby script that will ssh over to a server, run a given command, and fetch the output from it. Here\'s what I\'ve got so far, mostly adapted from the Prog

相关标签:
2条回答
  • 2021-02-10 19:58

    For this I recommend using the net-ssh gem: sudo gem install net-ssh: http://net-ssh.rubyforge.org/ssh/v2/api/index.html

    The code goes a little like this:

    require 'rubygems'
    require 'net/ssh'
    
    Net::SSH.start('your-server', 'username', :password => "password") do |ssh|
      puts ssh.exec!("ls -la")
    end
    
    0 讨论(0)
  • 2021-02-10 20:00

    Check out http://www.42klines.com/2010/08/14/what-to-expect-from-the-ruby-expect-library.html - it has some nice examples of using PTY with and without Ruby's expect.

    I often find it easier to only use PTY, as I can look at my "buffer" and work out what's happening.

    0 讨论(0)
提交回复
热议问题