 <p>Try to use this gem: <a href="https://github.com/net-ssh/net-ssh-gateway/" rel="nofollow">https://github.com/net-ssh/net-ssh-gateway/</a></p> <pre><code>require 'net/ssh/gateway' gateway = Net::SSH::Gateway.new(@jumpoffIp, @jumpoffUser) gateway.open('ont-db01-vip', 1521, 1521) gateway.open('ont-db02-vip', 1521, 1521) res = %x[sqlplus #{@sqlUsername}/#{@sqlPassword}@'#{@sqlUrl}' @scripts/populateASDB.sql &gt; output.txt] puts "populateDb output #{res}" gateway.shutdown! </code></pre>