class Scutil::Exec

Instantiate this class if you wish to use scutil as an object. For example:

exec = Scutil::Exec.new('severname', 'mas')

exec.exec_command('echo "foo"')

exec.exec_command('echo "bar"; sudo whoami', nil, 
                  { :scutil_force_pty => true, 
                    :scutil_verbose => true 
                  })

Attributes

hostname[R]
username[R]

Public Class Methods

new(hostname, username=nil, options={}) click to toggle source

Defaults to current user (ENV) if username is not specified.

# File lib/scutil/exec.rb, line 21
def initialize(hostname, username=nil, options={})
  @hostname = hostname
  @username = username.nil? ? ENV['USER'] : username
  @options  = options
end

Public Instance Methods

conn(pty_needed=false) click to toggle source

Exposes the raw Net::SSH::Connection::Session object associated with :hostname.

# File lib/scutil/exec.rb, line 40
def conn(pty_needed=false)
  Scutil.find_connection(@hostname, @username, pty_needed=false, @options)
end
download(remote, local=nil, options={}, &progress) click to toggle source

See Scutil.download. The options specified here will take precedence over those specified in the constructor.

# File lib/scutil/exec.rb, line 64
def download(remote, local=nil, options={}, &progress)
  set_options options
  Scutil.download(@hostname, @username, remote, local, @options, &progress)
end
exec_command(cmd, output=nil, options={}) click to toggle source

See Scutil.exec_command. Takes cmd and optionally output, and options. Other arguments specified at class initialization.

The options specified here will take precedence over those specified in the constructor.

# File lib/scutil/exec.rb, line 32
def exec_command(cmd, output=nil, options={})
  # Local map has precedence.
  set_options(options)
  Scutil.exec_command(@hostname, @username, cmd, output, @options)
end
set_options(options={}) click to toggle source

Alter the options set on this instance.

# File lib/scutil/exec.rb, line 45
def set_options(options={})
  @options.merge!(options)
end
upload(local, remote, options={}, &progress) click to toggle source

See Scutil.upload. The options specified here will take precedence over those specified in the constructor.

# File lib/scutil/exec.rb, line 57
def upload(local, remote, options={}, &progress)
  set_options options
  Scutil.upload(@hostname, @username, local, remote, @options, &progress)
end