Class: RemoteCommand
- Inherits:
-
Object
- Object
- RemoteCommand
- Defined in:
- lib/script_executor/remote_command.rb
Instance Attribute Summary collapse
-
#capture_output ⇒ Object
readonly
Returns the value of attribute capture_output.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#simulate ⇒ Object
readonly
Returns the value of attribute simulate.
-
#suppress_output ⇒ Object
readonly
Returns the value of attribute suppress_output.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #execute(commands, line_action) ⇒ Object
-
#initialize(params) ⇒ RemoteCommand
constructor
A new instance of RemoteCommand.
Constructor Details
#initialize(params) ⇒ RemoteCommand
Returns a new instance of RemoteCommand.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/script_executor/remote_command.rb', line 8 def initialize params params = sanitize_parameters params @host = params.delete(:domain) @host = params.delete(:host) if host.nil? and params[:host] @user = params.delete(:user) @suppress_output = params.delete(:suppress_output) @capture_output = params.delete(:capture_output) @simulate = params.delete(:simulate) = params end |
Instance Attribute Details
#capture_output ⇒ Object (readonly)
Returns the value of attribute capture_output.
6 7 8 |
# File 'lib/script_executor/remote_command.rb', line 6 def capture_output @capture_output end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
6 7 8 |
# File 'lib/script_executor/remote_command.rb', line 6 def host @host end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/script_executor/remote_command.rb', line 6 def end |
#simulate ⇒ Object (readonly)
Returns the value of attribute simulate.
6 7 8 |
# File 'lib/script_executor/remote_command.rb', line 6 def simulate @simulate end |
#suppress_output ⇒ Object (readonly)
Returns the value of attribute suppress_output.
6 7 8 |
# File 'lib/script_executor/remote_command.rb', line 6 def suppress_output @suppress_output end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
6 7 8 |
# File 'lib/script_executor/remote_command.rb', line 6 def user @user end |
Instance Method Details
#execute(commands, line_action) ⇒ Object
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/script_executor/remote_command.rb', line 22 def execute commands, line_action [:password] = HighLine.new.ask("Enter password for #{options[:user]}: ") { |q| q.echo = '*' } if [:password].nil? [:user] = user print commands, $stdout unless simulate storage = capture_output ? OutputBuffer.new : nil output = suppress_output ? nil : $stdout Net::SSH.start(host, user, ) do |session| session.exec(commands) do |channel, _, line| if ask_password?(line) channel.request_pty channel.send_data password + "\n" else output.print(line) if output storage.save(line.chomp) if storage line_action.call(line) if line_action end end session.loop # run the aggregated event loop end storage.buffer.join("\n") if storage end end |