Class: Z4box::Box
- Inherits:
-
Object
- Object
- Z4box::Box
- Defined in:
- lib/z4box.rb
Overview
ssh between nodes
Instance Method Summary collapse
- #eval(*c) ⇒ Object
-
#initialize(x) ⇒ Box
constructor
A new instance of Box.
- #spawn(e, p, *a) ⇒ Object
Constructor Details
#initialize(x) ⇒ Box
Returns a new instance of Box.
39 40 41 42 |
# File 'lib/z4box.rb', line 39 def initialize x u,b = x.split("@") @box = Net::SSH.start(b,u) end |
Instance Method Details
#eval(*c) ⇒ Object
63 64 65 66 67 |
# File 'lib/z4box.rb', line 63 def eval *c o = [] [c].flatten.map { |e| o << @box.exec!(e) } return o.join("\n") end |
#spawn(e, p, *a) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/z4box.rb', line 43 def spawn e, p, *a channel = ssh.open_channel do |ch| ch.exec "#{e} #{p} #{a.join(' ')}" do |ch, success| raise "could not execute command" unless success # "on_data" is called when the process writes something to stdout ch.on_data do |c, data| $stdout.print data end # "on_extended_data" is called when the process writes something to stderr ch.on_extended_data do |c, type, data| $stderr.print data end ch.on_close { puts "done!" } end end channel.wait end |