Module: Mina::SshHelpers
- Defined in:
- lib/mina/ssh_helpers.rb
Defined Under Namespace
Modules: Ssh
Instance Method Summary collapse
-
#ssh(cmd, options = {}) ⇒ Object
### ssh Executes a command via SSH.
-
#ssh_command ⇒ Object
### ssh_command Returns the SSH command to be executed.
Instance Method Details
#ssh(cmd, options = {}) ⇒ Object
### ssh Executes a command via SSH.
Returns nothing usually, but if ‘{ return: true }` is given, returns the STDOUT output of the SSH session.
‘options` is a hash of options:
- `:pretty` - Prettify the output if true.
- `:return` - If set to true, returns the output.
Example
ssh("ls", return: true)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mina/ssh_helpers.rb', line 22 def ssh(cmd, ={}) require 'shellwords' cmd = cmd.join("\n") if cmd.is_a?(Array) script = Shellwords.escape(cmd) if [:return] == true `#{ssh_command} -- #{script}` elsif simulate_mode? Ssh.simulate(cmd, ssh_command) else result = Ssh.invoke(script, self) Ssh.ensure_successful result, self end end |
#ssh_command ⇒ Object
### ssh_command Returns the SSH command to be executed.
set :domain, 'foo.com'
set :user, 'diggity'
puts ssh_command
#=> 'ssh [email protected]'
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mina/ssh_helpers.rb', line 49 def ssh_command args = domain!.dup args = "#{user}@#{args}" if user? args << " -i #{identity_file}" if identity_file? args << " -p #{port}" if port? args << " -A" if forward_agent? args << " #{}" if args << " -t" "ssh #{args}" end |