Skip to content

Instantly share code, notes, and snippets.

@draftcode
Created June 2, 2013 10:46
Show Gist options
  • Select an option

  • Save draftcode/5693276 to your computer and use it in GitHub Desktop.

Select an option

Save draftcode/5693276 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
require 'net/ssh'
Net::SSH.start(HOSTNAME, USERNAME) do |ssh|
ssh.open_channel do |channel|
channel.exec('ruby') do |ch, success|
abort 'cannot execute ruby' unless success
ch.on_data do |c, data|
$stdout.puts("received #{data}")
end
ch.send_data(<<-RUBY_CODE)
p($stdin.read)
RUBY_CODE
ch.send_data("\C-d\n")
ch.send_data("one\n")
ch.send_data("two\n")
ch.send_data("three\n")
ch.eof!
end
end
ssh.loop
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment