Skip to content

Commit

Permalink
Add support to send data on standard input when executing a command
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiendupont committed Oct 5, 2018
1 parent b66b7ad commit fd9cb28
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/gems/pending/util/MiqSshUtil.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_file(from, to)
end
end

def exec(cmd, doneStr = nil)
def exec(cmd, doneStr = nil, stdin = nil)
errBuf = ""
outBuf = ""
status = nil
Expand Down Expand Up @@ -94,13 +94,19 @@ def exec(cmd, doneStr = nil)
end

$log.debug "MiqSshUtil::exec - Command: #{cmd} started." if $log
channel.exec(cmd) { |_channel, success| raise "MiqSshUtil::exec - Could not execute command #{cmd}" unless success }
channel.exec(cmd) do |chan, success|
raise "MiqSshUtil::exec - Could not execute command #{cmd}" unless success
if stdin.present?
chan.send_data(stdin)
chan.eof!
end
end
end
ssh.loop
end
end # def exec

def suexec(cmd_str, doneStr = nil)
def suexec(cmd_str, doneStr = nil, stdin = nil)
errBuf = ""
outBuf = ""
prompt = ""
Expand Down Expand Up @@ -191,7 +197,13 @@ def suexec(cmd_str, doneStr = nil)

$log.debug "MiqSshUtil::suexec - Command: [#{cmd_str}] started." if $log
su_command = @su_user == 'root' ? "su -l\n" : "su -l #{@su_user}\n"
channel.exec(su_command) { |_channel, success| raise "MiqSshUtil::suexec - Could not execute command #{cmd}" unless success }
channel.exec(su_command) do |chan, success|
raise "MiqSshUtil::suexec - Could not execute command #{cmd}" unless success
if stdin.present?
chan.send_data(stdin)
chan.eof!
end
end
end
end
ssh.loop
Expand Down

0 comments on commit fd9cb28

Please sign in to comment.