Class: SSHKit::Interactive::Command
- Inherits:
-
Object
- Object
- SSHKit::Interactive::Command
- Defined in:
- lib/sshkit/interactive/command.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#remote_command ⇒ Object
readonly
Returns the value of attribute remote_command.
Instance Method Summary collapse
-
#execute ⇒ Object
Run the command on the remote host via SSH binary.
-
#initialize(host, remote_command = nil) ⇒ Command
constructor
Instantiate new interactive SSHKit command wrapper.
-
#ssh_cmd_args ⇒ Object
SSH command arguments.
-
#to_s ⇒ Object
Complete command.
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
#host ⇒ Object (readonly)
Returns the value of attribute host.
4 5 6 |
# File 'lib/sshkit/interactive/command.rb', line 4 def host @host end |
#remote_command ⇒ Object (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
#execute ⇒ Object
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_args ⇒ Object
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_s ⇒ Object
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 |