Sha256: 290c45f94e57dd1046d26cb15402fd61ac0c0797d534cc352f255c8224eff7be

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'open3'
require 'hydra/io'
module Hydra #:nodoc:
  # Read and write with an ssh connection. For example:
  #   @ssh = Hydra::SSH.new(
  #     'localhost', # connect to this machine
  #     '/home/user', # move to the home directory
  #     "ruby hydra/test/echo_the_dolphin.rb" # run the echo script
  #   )
  #   @message = Hydra::Messages::TestMessage.new("Hey there!")
  #   @ssh.write @message
  #   puts @ssh.gets.text
  #     => "Hey there!"
  #
  # Note that what ever process you run should respond with Hydra messages.
  class SSH
    include Open3
    include Hydra::MessagingIO

    # Initialize new SSH connection. The single parameters is passed
    # directly to ssh for starting a connection. So you can do:
    #  Hydra::SSH.new('localhost')
    #  Hydra::SSH.new('user@server.com')
    #  Hydra::SSH.new('-p 3022 user@server.com')
    # etc..
    def initialize(connection_options, directory, command)
      @writer, @reader, @error = popen3("ssh #{connection_options}")
      @writer.write("cd #{directory}\n")
      @writer.write(command+"\n")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hydra-0.3.0 lib/hydra/ssh.rb