Table Of Contents

Previous topic

Capistrano

Next topic

RubyGems

This Page

Net::SSH

http://net-ssh.rubyforge.org/

samples

基本

#!/usr/bin/ruby

require 'rubygems'
require 'net/ssh'

HOST='host'
USER='user'

Net::SSH.start(HOST, USER) do |ssh|
    print(ssh.exec!('ls ~'))
end

channel

ssh.open_channel do |channel|
  channel.exec("/invoke/some/command") do |ch, success|
    abort "could not execute command" unless success

    channel.on_data do |ch, data|
      puts "got stdout: #{data}"
      channel.send_data "something for stdin\n"
    end

    channel.on_extended_data do |ch, type, data|
      puts "got stderr: #{data}"
    end

    channel.on_close do |ch|
      puts "channel is closing!"
    end
  end
end

ssh.loop
inserted by FC2 system