Class: SSHKit::Backend::Netssh

Inherits:
Object
  • Object
show all
Defined in:
lib/addon/sshkit_monkey_patch.rb

Instance Method Summary collapse

Instance Method Details

#put(strings, remote, options = {}) ⇒ Object



6
7
8
9
# File 'lib/addon/sshkit_monkey_patch.rb', line 6

def put strings, remote, options = {}
    local = StringIO.new strings
    upload! local, remote, options
end

#su_run(user, cmd) ⇒ Object Also known as: su_execute



11
12
13
# File 'lib/addon/sshkit_monkey_patch.rb', line 11

def su_run user, cmd
  execute %Q(su - #{user} -c "#{cmd}")
end

#sudo(cmd) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/addon/sshkit_monkey_patch.rb', line 16

def sudo cmd
    SSHKit::Backend::Netssh.config.pty = true
    # p host
    password = host.password
    execute %Q( echo #{password} | sudo -kS bash -c "#{cmd}" )

    # execute %Q(sudo bash -c "#{cmd}"), interaction_handler: {
    #     /\(yes\/no\)/i => "yes\n",
    #     /[sudo] password/i => "#{password}\n",
    # }

end