Class: Ajimi::Server::Ssh
- Inherits:
-
Object
- Object
- Ajimi::Server::Ssh
- Defined in:
- lib/ajimi/server/ssh.rb
Instance Method Summary collapse
- #command_exec(cmd) ⇒ Object
-
#initialize(options = {}) ⇒ Ssh
constructor
A new instance of Ssh.
- #net_ssh ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Ssh
Returns a new instance of Ssh.
6 7 8 9 10 |
# File 'lib/ajimi/server/ssh.rb', line 6 def initialize( = {}) @host = [:host] @user = [:user] @key = [:key] end |
Instance Method Details
#command_exec(cmd) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ajimi/server/ssh.rb', line 16 def command_exec(cmd) = {} = { keys: @key } = .merge() stdout = "" stderr = "" net_ssh.start(@host, @user, ) do |session| session.exec!(cmd) do |channel, stream, data| stdout << data if stream == :stdout stderr << data if stream == :stderr end end $stderr.puts stderr unless stderr == "" stdout end |
#net_ssh ⇒ Object
12 13 14 |
# File 'lib/ajimi/server/ssh.rb', line 12 def net_ssh Net::SSH end |