Class: SSH::Ident::ShellCmd

Inherits:
Object
  • Object
show all
Defined in:
lib/ssh/ident/shell_cmd.rb

Overview

runs a shell command [in the context of the agent]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ShellCmd

Returns a new instance of ShellCmd.



10
11
12
13
14
15
16
17
18
19
# File 'lib/ssh/ident/shell_cmd.rb', line 10

def initialize(options = {})
  fail 'command not set' unless options.key?(:command)
  @command = options[:command]
  @own_env = options[:own_env]
  @quote_command = options[:quote_command]
  @quote_command ||= true
  @agent_file = options[:agent_file]
  @output = options[:output]
  @own_env = true if @agent_file
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



8
9
10
# File 'lib/ssh/ident/shell_cmd.rb', line 8

def command
  @command
end

#own_envObject (readonly)

Returns the value of attribute own_env.



8
9
10
# File 'lib/ssh/ident/shell_cmd.rb', line 8

def own_env
  @own_env
end

#resultObject (readonly)

Returns the value of attribute result.



8
9
10
# File 'lib/ssh/ident/shell_cmd.rb', line 8

def result
  @result
end

Instance Method Details

#runObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ssh/ident/shell_cmd.rb', line 21

def run
  command = @command.dup
  cmd = []
  cmd << '/usr/bin/env' << '-i' if @own_env

  command = ". #{@agent_file} > /dev/null 2>/dev/null; #{command}" if @agent_file
  command = "\"#{command}\"" if @quote_command
  cmd << '/bin/sh' << "-c #{command}"
  cmd << '>/dev/null' << '2>/dev/null' unless @output
  full_command = cmd.join(' ')

  # puts "running: #{full_command}"
  @result = `#{full_command}`
  @result = nil if $CHILD_STATUS.to_i != 0
  @result
end