# Net::Telnet won't close properly

**URL:** <https://www.ruby-forum.com/t/net-telnet-wont-close-properly/123339>\
**Category:** Ruby\
**Created:** [December 16, 2007, 6:57pm UTC](https://www.ruby-forum.com/t/net-telnet-wont-close-properly/123339 "2007-12-16T18:57:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jackster](https://www.ruby-forum.com/u/jackster)\
**Post date:** [December 16, 2007, 6:57pm UTC](https://www.ruby-forum.com/t/net-telnet-wont-close-properly/123339/1 "2007-12-16T18:57:44Z")

</div>

Hi Ruby Forum!

I’m hoping you can help my code to close properly.  
The script logs into a cisco router, logs into enable mode then runs  
“show clock” and prints the output…this all works fine. The problem  
is, the script times out and never runs the “close” command.

Here is the error I get:

/usr/local/lib/ruby/1.8/net/telnet.rb:551:in `waitfor’: timed out while  
waiting for more data (Timeout::Error)

## Here is the code: ---------------------------------- Begin

require ‘net/telnet’

CISCO = “172.30.152.1” #Enter the IP address here  
USER = “username” #Enter username here  
PASS = “password” #Enter password here  
ENABLEPASS = “myenablepassword”  
SHOCLOCK = “show clock”

tn = Net::Telnet::new(“Host” =\> CISCO,  
“Timeout” =\> 5,  
“Prompt” =\> /^\Username:/ )

## tn.cmd("\n#{USER}") { |c| print c } tn.cmd(PASS) { |c| print c } tn.print(“enable”) { |c| print c } #tn.waitfor(“Password: “) { |c| print c } tn.print(”\n#{ENABLEPASS}”) { |c| print c } tn.cmd("\n#{SHOCLOCK}\n") { |c| print c }—\>DISPLAYS “SH CLOCK” BUT HANGS HERE tn.close ---------\> THE SCRIPT TIMES OUT BEFORE EVER GETTING TO TN.CLOSE ----------------------------------- End

Any thoughts or suggestions would be greatly appreciated!  
Thanks

jackster
