Net::Telnet won't close properly

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