Sha256: 51c3fbc023253901e7c8af9ee50ca742f66a523db5dc25c48f665218610d2b9e

Contents?: true

Size: 715 Bytes

Versions: 2

Compression:

Stored size: 715 Bytes

Contents

require 'net/telnet'

class CheckpointKnocker
  class << self
    def knock(options={})
      host = options[:host]
      port = options[:port]
      user = options[:user]
      pass = options[:pass]

      begin
        h = Net::Telnet.new('Host' => host,
                            'Port' => port)

        h.waitfor(/User:/) { |c| print c }
        h.print("#{user}\n") { |c| print c }

        h.waitfor(/password:/) { |c| print c }
        h.print("#{pass}\n") { |c| print c }

        h.waitfor(/authenticated/) { |c| print c }
        h.print("1") { |c| print c }

        h.waitfor(/authorized/) { |c| print c }
        h.close
      rescue Errno::ECONNRESET
        # finished
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
checkpoint_knocker-0.0.2 lib/checkpoint_knocker.rb
checkpoint_knocker-0.0.1 lib/checkpoint_knocker.rb