File: auth-forward.rb

package info (click to toggle)
libnet-ssh-ruby 1.1.2-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,472 kB
  • ctags: 2,465
  • sloc: ruby: 10,848; makefile: 17
file content (41 lines) | stat: -rw-r--r-- 926 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'rubygems'

$:.unshift "../lib"
require 'net/ssh'



Net::SSH.start( 'localhost', { :verbose => :debug, :forward_agent => true } ) do |session|
#Net::SSH.start( 'localhost' ) do |session|

  def exec( command )
    lambda do |channel|
      channel.exec command
      channel.on_data do |ch,data|
        ch[:data] ||= ""
        ch[:data] << data
      end
      channel.on_extended_data do |ch,type,data|
        ch[:extended_data] ||= []
        ch[:extended_data][type] ||= ""
        ch[:extended_data][type] << data
      end
    end
  end

  c = session.open_channel( &exec( "ssh -A munkyii.nodnol.org ssh-add -l" ) )

  session.loop

  puts "----------------------------------"
  if c.valid?
    puts c[:data]
    if c[:extended_data] && c[:extended_data][1]
      puts "-- stderr: --"
      puts c[:extended_data][1]
    end
  else
    puts "channel was not opened: #{c.reason} (#{c.reason_code})"
  end

end