I am trying to write a Ruby script that will go to the server, run the given command and extract the output from it. Here is what I have so far, mostly adapted from Programming Ruby :
require 'pty' require 'expect' $expect_verbose = true PTY.spawn("ssh root@x.y ") do |reader, writer, pid| reader.expect(/ root@x.y password:.*/) writer.puts("password") reader.expect(/.*/) writer.puts("ls -l") reader.expect(/.*/) answer = reader.gets puts "Answer = #{answer}" end
Unfortunately, all I get is the following:
Answer = .y password:
Any idea what I did wrong and how to facilitate this?
source share