Net/telnet session times out

#Subject: Re: net/telnet session times out

···

Wybo Dekker [mailto:wybo@servalys.nl] wrote:

#
#.. here it comes...

I think the telnet#login method is waiting for the text "login" and
therefore cannot catch the "Username" text prompt.

Try using #waitfor...

Eg,

--------------------------------

cat ttest.rb

# test using waitfor

time_start = Time::new

require 'net/telnet'
host = "10.1.1.1"
tn = Net::Telnet::new( \
           "Host" => host, # default: "localhost"
           "Port" => 23, # default: 23
           "Binmode" => false, # default: false
           "Output_log" => "output_log", # default: nil (no output)
           "Dump_log" => "dump_log", # default: nil (no output)
           "Prompt" => /[$%#>]/, # default: /[$%#>] \z/n
           "Telnetmode" => true, # default: true
           "Timeout" => 5, # default: 10
           "Waittime" => 0 # default: 0
)
tn.waitfor(/ogin:/) {|c| print c}

# ^ in your case,
#------------^ replace this w "tn.waitfor(/username/) {|c| print c}"
#

tn.puts "test"
tn.waitfor(/assword/) {|c| print c}
tn.puts "test's password"
tn.cmd("uname -an") { |c| print c }
tn.cmd("ls -la") { |c| print c }
tn.cmd("exit") {|c| print c}
tn.close

puts
puts "#{Time.now - time_start} seconds"

ttest.rb

Red Hat Linux release 6.2 (Zoot)
Kernel 2.2.16-3 on an i586
login: test
Password:
uname -an
Last login: Tue Jul 5 22:33:55 from test-pc
You have new mail.
unknown terminal "network"
$ uname -an
Linux test.test.testdomain 2.2.16-3 #1 Mon Jun 19 18:10:14 EDT 2000 i586
unknown
$ ls -la
total 17
drwx------ 3 botp botp 1024 Jun 6 16:29 .
drwxr-xr-x 13 root root 1024 Mar 8 23:10 ..
-rw------- 1 botp botp 10285 Jul 5 22:35 .bash_history
-rw-r--r-- 1 botp botp 24 Jul 30 2001 .bash_logout
-rw-r--r-- 1 botp botp 230 Jul 30 2001 .bash_profile
-rw-r--r-- 1 botp botp 124 Jul 30 2001 .bashrc
drwxr-xr-x 2 root root 1024 May 20 02:22 scripts
$ exit
logout
'network': unknown terminal type.

0.797 seconds

------------------------

Is that ok?

kind regards -botp