Class: MyExec
- Inherits:
-
Object
- Object
- MyExec
- Defined in:
- lib/Framework/MyExec.rb
Instance Method Summary collapse
- #execute(command, exec_mode = 'off') ⇒ Object
-
#initialize(method, exec_mode = 'off') ⇒ MyExec
constructor
A new instance of MyExec.
- #set_ssh(server, user, password) ⇒ Object
- #show_variables ⇒ Object
Constructor Details
#initialize(method, exec_mode = 'off') ⇒ MyExec
Returns a new instance of MyExec.
4 5 6 7 |
# File 'lib/Framework/MyExec.rb', line 4 def initialize(method, exec_mode='off') @method = method @exec_mode = exec_mode end |
Instance Method Details
#execute(command, exec_mode = 'off') ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/Framework/MyExec.rb', line 26 def execute(command, exec_mode = 'off') exec_local = @exec_mode exec_local = 'on' if exec_mode == 'on' result_string = '' STDOUT.sync = true Net::SSH.start(@ssh_server, @ssh_user, :password => @ssh_password) do |ssh| time1 = Time.new puts time1.strftime('%Y-%m-%d %H:%M:%S') + " calling: #{command}" puts time1.strftime('%Y-%m-%d %H:%M:%S') + ' exec mode: ' + exec_local result_string = ssh.exec!(command) if exec_local == 'on' time2 = Time.new puts time2.strftime('%Y-%m-%d %H:%M:%S') + ' executed' return result_string end end |
#set_ssh(server, user, password) ⇒ Object
20 21 22 23 24 |
# File 'lib/Framework/MyExec.rb', line 20 def set_ssh(server, user, password) @ssh_server = server @ssh_user = user @ssh_password = password end |
#show_variables ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/Framework/MyExec.rb', line 9 def show_variables puts "Method: #{@method}" puts 'Ssh' puts "Server: #{@ssh_server}" puts "User: #{@ssh_user}" puts "Password: #{@ssh_password}" puts "ExecMode: #{@exec_mode}" end |