Net::Telnet won't close properly

  • Thread starter jackster the jackle
  • Start date
J

jackster the jackle

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top