Class: SSHKit::Interactive::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/sshkit/interactive/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, remote_command = nil) ⇒ Command

Instantiate new interactive SSHKit command wrapper.



10
11
12
13
# File 'lib/sshkit/interactive/command.rb', line 10

def initialize(host, remote_command = nil)
  @host           = host
  @remote_command = remote_command
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



4
5
6
# File 'lib/sshkit/interactive/command.rb', line 4

def host
  @host
end

#remote_commandObject (readonly)

Returns the value of attribute remote_command.



4
5
6
# File 'lib/sshkit/interactive/command.rb', line 4

def remote_command
  @remote_command
end

Instance Method Details

#executeObject

Run the command on the remote host via SSH binary.



16
17
18
# File 'lib/sshkit/interactive/command.rb', line 16

def execute
  system(to_s)
end

#ssh_cmd_argsObject

SSH command arguments



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/sshkit/interactive/command.rb', line 21

def ssh_cmd_args
  args = []

  args << '-t'
  args << '-A' if forward_agent?
  args << "-p #{port}" if port
  args << "-l #{user}" if user
  args << %Q{-o "PreferredAuthentications #{auth_methods.join(',')}"} if auth_methods.count > 0
  args << %Q{-o "ProxyCommand #{proxy_command}"} if proxy
  args << %Q{-o "HostName #{host_name}"} if host_name

  keys.each do |key|
    args << "-i #{key}"
  end

  args
end

#to_sObject

Complete command



40
41
42
43
44
45
46
47
# File 'lib/sshkit/interactive/command.rb', line 40

def to_s
  [
    :ssh,
    *ssh_cmd_args,
    host.hostname,
    %Q{'$SHELL -l -c "#{remote_command.to_command}"'}
  ].reject(&:empty?).join(' ')
end