Sha256: 1916f3fddaa5a9e44716b818df5987d35d839164f7c41f0951bf51ef6bf74afd

Contents?: true

Size: 1.39 KB

Versions: 33

Compression:

Stored size: 1.39 KB

Contents

require 'open3'
require 'hydra/messaging_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 first parameter is passed directly to ssh for starting a connection.
    # The second parameter is the directory to CD into once connected.
    # The third parameter is the command to run
    # So you can do:
    #   Hydra::SSH.new('-p 3022 user@server.com', '/home/user/Desktop', 'ls -l')
    # To connect to server.com as user on port 3022, then CD to their desktop, then
    # list all the files.
    def initialize(connection_options, directory, command)
      @writer, @reader, @error = popen3("ssh -tt #{connection_options}")
      @writer.write("mkdir -p #{directory}\n")
      @writer.write("cd #{directory}\n")
      @writer.write(command+"\n")
    end

    # Close the SSH connection
    def close
      @writer.write "exit\n"
      super
    end
  end
end

Version data entries

33 entries across 33 versions & 8 rubygems

Version Path
ngauthier-hydra-0.24.0 lib/hydra/ssh.rb
nulogy-hydra-0.26.0 lib/hydra/ssh.rb
arturop-hydra-0.25.0 lib/hydra/ssh.rb
arturop-hydra-0.24.0 lib/hydra/ssh.rb
hydra-0.24.0 lib/hydra/ssh.rb
nulogy-hydra-0.23.2.1 lib/hydra/ssh.rb
justinf-hydra-0.23.8 lib/hydra/ssh.rb
justinf-hydra-0.23.7 lib/hydra/ssh.rb
justinf-hydra-0.23.6 lib/hydra/ssh.rb
justinf-hydra-0.23.5 lib/hydra/ssh.rb
justinf-hydra-0.23.4 lib/hydra/ssh.rb
arturop-hydra-0.23.4 lib/hydra/ssh.rb
sskirby-hydra-0.23.3 lib/hydra/ssh.rb
hydra-0.23.3 lib/hydra/ssh.rb
causes-hydra-0.21.0 lib/hydra/ssh.rb
hydra-0.23.2 lib/hydra/ssh.rb
hydra-0.23.1 lib/hydra/ssh.rb
hydra-0.23.0 lib/hydra/ssh.rb
hydra-0.22.2 lib/hydra/ssh.rb
hydra-0.22.1 lib/hydra/ssh.rb