class SSH::Ident::ShellCmd

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

Attributes

command[R]
own_env[R]
result[R]

Public Class Methods

new(options = {}) click to toggle source
# 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

Public Instance Methods

run() click to toggle source
# 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