Method: Remoting::Ssh#exec

Defined in:
lib/remoting/ssh.rb

#exec(commands) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/remoting/ssh.rb', line 18

def exec(commands)

  if interactive?
    ssh = %(ssh #{user}@#{host})
    Kernel.exec ssh + %( -t '#{commands.join("; ")}')  # this will replace the current process and will never return the shell back
  else
    Net::SSH.start(host, user) do |ssh|
  
      ssh.open_channel do |channel|
        channel.exec(commands.join(";")) do |ch, success|
          unless success
            abort
          end
        
          channel.on_data do |ch, data|
            say "#{data}"
          end

          channel.on_extended_data do |ch, type, data|
            shell.error "#{data}"
          end

          channel.on_close do |ch|
            shell.bold "channel is closing!\n"
          end
        end
      end

      ssh.loop 
    end        
  end
  
end