lib/backup/remote/command.rb in backup-remote-0.0.12 vs lib/backup/remote/command.rb in backup-remote-0.0.13
- old
+ new
@@ -4,63 +4,69 @@
require 'sshkit/sudo'
module Backup
module Remote
-
class Command
- include SSHKit::DSL
+ include SSHKit::DSL
- def run_ssh_cmd(hostname, ssh_user, ssh_pass, cmd)
- host = SSHKit::Host.new({hostname: hostname, user: ssh_user})
- host.password = ssh_pass
+ def run_ssh_cmd(hostname, ssh_user, ssh_pass, cmd)
+ host = SSHKit::Host.new({hostname: hostname, user: ssh_user})
+ host.password = ssh_pass
- #srv = ssh_user+'@'+hostname
- all_servers = [host]
+ #srv = ssh_user+'@'+hostname
+ all_servers = [host]
- output = ''
+ output = ''
- on all_servers do |srv|
- #SSHKit::Coordinator.new(host).each in: :sequence do
- as(user: ssh_user) do
- #execute(cmd)
- output = capture(cmd)
- end
- end
+ on all_servers do |srv|
+ #SSHKit::Coordinator.new(host).each in: :sequence do
+ as(user: ssh_user) do
+ #execute(cmd)
+ output = capture(cmd)
+ end
+ end
- #
- return { res: 1, output: output }
- end
+ #
+ return { res: 1, output: output }
- def run_ssh_cmd_sudo(hostname, ssh_user, ssh_pass, cmd, handler=nil)
- host = SSHKit::Host.new("#{ssh_user}@#{hostname}")
- host.password = ssh_pass
+ rescue => e
+ {
+ res: 0,
+ output: output,
+ error: e.message
+ }
+ end
- on host do |host|
- execute("#{cmd}", interaction_handler: handler)
- end
+ def run_ssh_cmd_sudo(hostname, ssh_user, ssh_pass, cmd, handler=nil)
+ host = SSHKit::Host.new("#{ssh_user}@#{hostname}")
+ host.password = ssh_pass
- #
- return {res: 1, output: ""}
+ on host do |host|
+ execute("#{cmd}", interaction_handler: handler)
+ end
- rescue => e
- {
- res: 0,
- error: e.message
- }
- end
+ #
+ return {res: 1, output: ""}
- 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
+ rescue => e
+ {
+ res: 0,
+ error: e.message
+ }
+ end
+
+ 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
def ssh_download_file(hostname, ssh_user, ssh_pass, remote_filename, dest_filename)
return ssh_download_file_sshkit(hostname, ssh_user, ssh_pass, remote_filename, dest_filename)