I'm generating a data feed on the local machine, that I want to pipe into a remote process via Net::SSH.
Something like
echo foosball | sed 's/foo/bar/g'
Just that the echo foosball
part would be the data feed on the local machine.
What I'm NOT looking for is:
data = "foosball"
ssh.exec!("echo #{data} | sed 's/foo/bar/g'")
I really want a stream of data piped into the process in real time ;)
Okay, I figured it out:
#!/usr/bin/env ruby
require 'rubygems'
require 'net/ssh'
res = ""
c = Net::SSH.start("127.0.0.1", "xxx", :password => "xxx")
c.open_channel do |channel|
channel.exec("sed 's/foo/bar/g'") do |ch, success|
channel.on_data do |ch,data|
res << data
end
channel.send_data "foosball"
channel.eof!
end
end
c.loop
puts res # => "barsball"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With