Class: Remoting::Ssh
- Inherits:
-
Object
- Object
- Remoting::Ssh
- Defined in:
- lib/remoting/ssh.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #exec(commands) ⇒ Object
-
#initialize(*args) ⇒ Ssh
constructor
A new instance of Ssh.
-
#interactive? ⇒ Boolean
~ exec.
- #shell ⇒ Object
Constructor Details
#initialize(*args) ⇒ Ssh
Returns a new instance of Ssh.
8 9 10 11 |
# File 'lib/remoting/ssh.rb', line 8 def initialize(*args) = args. @host, @user, @interactive = .values_at(:host, :user, :interactive) end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
6 7 8 |
# File 'lib/remoting/ssh.rb', line 6 def host @host end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
6 7 8 |
# File 'lib/remoting/ssh.rb', line 6 def user @user end |
Instance Method Details
#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 |
#interactive? ⇒ Boolean
~ exec
52 53 54 |
# File 'lib/remoting/ssh.rb', line 52 def interactive? !!@interactive end |