Net-ssh, send_data not having visible effect

Hi,

I would like to use net-ssh v2 to fire up a process on a remote host and
to immediately pipe data into the remote process. Despite this being a
trivial thing to do and threads like this having popped up in various
places on the Internet, I haven’t yet been able to figure out how to do
this.

Here is my code:

require ‘net/ssh’

puts “net.ssh.start”
Net::SSH.start( ‘my-remote-host.example’,
‘mh’,
:keys => [ ‘/home/mh/.ssh/my-private-key’ ]
) do |ssh|
ssh.open_channel do |channel|
channel.exec(“tee /tmp/test”) do |ch, success|
channel.on_data do |ch,data|
puts “stdout: #{data}”
end
if success
puts “tee has begun executing”
puts “sending data 2”
channel.send_data “data 2”
puts “sent data 2”
channel.eof!
puts “eof sent”
else
puts “tee could not be invoked!”
end
end
end
puts “ssh.loop”
ssh.loop
end
puts “finis”

With this code, I finally have the statements executing in the right
order:

net.ssh.start
ssh.loop
tee has begun executing
sending data 2
sent data 2
eof sent
finis

and the /tmp/test file written on the remote side is created, but it is
empty.

Any ideas how to do this right?

All examples that can be found on the net deal with a program that
starts talking to the local ruby script first. My remote program
doesn’t, and so I cannot use an on_data callback to issue my output.

And an on_connect callback seems to be missing.

What am I doing wrong?

Greetings
Marc

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs