Class: Hydra::SSH

Inherits:
Object
  • Object
show all
Includes:
MessagingIO, Open3
Defined in:
lib/hydra/ssh.rb

Overview

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.

Instance Method Summary collapse

Methods included from MessagingIO

#close, #gets, #write

Constructor Details

#initialize(connection_options, directory, command) ⇒ SSH

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('[email protected]')
Hydra::SSH.new('-p 3022 [email protected]')

etc..



26
27
28
29
30
# File 'lib/hydra/ssh.rb', line 26

def initialize(connection_options, directory, command)
  @writer, @reader, @error = popen3("ssh #{connection_options}")
  @writer.write("cd #{directory}\n")
  @writer.write(command+"\n")
end