# Net::Telnet won't close properly

**URL:** <https://rubytalk.org/t/net-telnet-wont-close-properly/43069>\
**Category:** ruby-talk\
**Created:** [16 December 2007 18:03 UTC](https://rubytalk.org/t/net-telnet-wont-close-properly/43069 "2007-12-16T18:03:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Sheahan](https://avatars.discourse-cdn.com/v4/letter/j/ad7895/32.png) [@John\_Sheahan](https://rubytalk.org/u/John_Sheahan)\
**Post date:** [16 December 2007 18:03 UTC](https://rubytalk.org/t/net-telnet-wont-close-properly/43069/1 "2007-12-16T18:03:45Z")

</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  
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
