Class: Backup::Remote::Command
- Inherits:
-
Object
- Object
- Backup::Remote::Command
- Includes:
- SSHKit::DSL
- Defined in:
- lib/backup/remote/command.rb
Class Method Summary collapse
Instance Method Summary collapse
- #run_ssh_cmd(hostname, ssh_user, ssh_pass, cmd) ⇒ Object
- #run_ssh_cmd_sudo(hostname, ssh_user, ssh_pass, cmd, handler = nil) ⇒ Object
- #ssh_download_file(hostname, ssh_user, ssh_pass, remote_filename, dest_filename) ⇒ Object
Class Method Details
.interaction_handler_pwd(user, pwd, host = '') ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/backup/remote/command.rb', line 51 def self.interaction_handler_pwd(user, pwd, host='') { "#{user}@#{host}'s password:" => "#{pwd}\n", /#{user}@#{host}'s password: */ => "#{pwd}\n", "password: " => "#{pwd}\n", "password:" => "#{pwd}\n", "Password: " => "#{pwd}\n", } end |
Instance Method Details
#run_ssh_cmd(hostname, ssh_user, ssh_pass, cmd) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/backup/remote/command.rb', line 15 def run_ssh_cmd(hostname, ssh_user, ssh_pass, cmd) srv = ssh_user+'@'+hostname all_servers = [srv] output = '' on all_servers do |srv| as(user: ssh_user) do #execute(cmd) output = capture(cmd) end end # return { res: 1, output: output } end |
#run_ssh_cmd_sudo(hostname, ssh_user, ssh_pass, cmd, handler = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/backup/remote/command.rb', line 33 def run_ssh_cmd_sudo(hostname, ssh_user, ssh_pass, cmd, handler=nil) host = SSHKit::Host.new("#{ssh_user}@#{hostname}") host.password = ssh_pass on host do |host| execute("#{cmd}", interaction_handler: handler) end # return {res: 1, output: ""} rescue => e { res: 0, error: e. } end |
#ssh_download_file(hostname, ssh_user, ssh_pass, remote_filename, dest_filename) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/backup/remote/command.rb', line 62 def ssh_download_file(hostname, ssh_user, ssh_pass, remote_filename, dest_filename) host = SSHKit::Host.new("#{ssh_user}@#{hostname}") host.password = ssh_pass on host do |host| download! remote_filename, dest_filename end # return {res: 1, output: ""} rescue => e { res: 0, error: e. } end |