Module: Oats::Ossh
- Defined in:
- lib/oats/ossh.rb
Overview
Implement Oats.rssh and Oats.rput functionality. See Oats.rssh documentation.
Class Method Summary collapse
Class Method Details
.run(cmd_file, dir = nil, host = nil, username = nil, rput = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/oats/ossh.rb', line 8 def Ossh.run(cmd_file, dir = nil , host = nil, username = nil, rput = nil) username ||= Oats.data['ssh']['username'] host ||= Oats.data['ssh']['host'] raise(OatsOsshMissingInput, "Ossh plink requires a host.") unless host if username == 'root' cmd = "plink #{host} -l #{Oats.data['ssh']['root_sudo_username']} " cmd_file = 'sudo -u root ' + cmd_file else cmd = "plink #{host} -l #{username} " end if rput source_cmd = 'echo' if File.exist?(cmd_file) cmd_file.gsub! /\//, '\\' source_cmd = 'type' end cmd = "#{source_cmd} #{cmd_file} | #{cmd}\"/home/levent.atasoy/bin/oats_put_file.sh #{dir}\"" else if dir cmd += "\"cd #{dir} ; #{cmd_file} 2>&1\"" else cmd += "\"#{cmd_file} 2>&1\"" end end $log.info cmd `#{cmd}` end |