I have some code that will login to my cisco router and run a basic
command.
The problem is, I need to get into enable mode to run additional
command. Getting into enable mode requires typing “enable”, waiting for
the prompt "Password: " then entering another password.
This code works and gets me into the router but not in enable mode:
#!/usr/local/bin/ruby
require ‘net/telnet’
CISCO = “172.31.1.1” #Enter the IP address here
USER = “jsmith” #Enter username here
PASS = “mypassword” #Enter password here
ENABLE = “myenablepass” #Enter enable password here
On Dec 14, 2007 6:27 PM, jackster the jackle [email protected]
wrote:
“Timeout” => 5,
taking my password for some reason and I know the password is good.
tn.waitfor(/Password: /)
tn.cmd(ENABLE) { |c| print c }
tn.cmd “Match” => /Password[: ]*\z/, “String” => “enable”
works just fine on our catalysts, I am not exactly sure how waitfor
and cmd interact, but the Match parameter should do the trick.
All truth passes through three stages. First, it is ridiculed. Second,
it is violently opposed. Third, it is accepted as being self-evident.
Schopenhauer (attr.)
You don’t have \n on the end of ENABLE, but I don’t know if that makes
a difference…
–Jeremy
On Dec 14, 2007 12:27 PM, jackster the jackle [email protected]
wrote:
“Timeout” => 5,
taking my password for some reason and I know the password is good.
tn.waitfor(/Password: /)
tn.cmd(ENABLE) { |c| print c }
tn.cmd(“sh run\n”) { |c| print c }
Any ideas to get me into enable mode here would be greatly appreciated.
thanks
jackster
On Dec 16, 2007 11:36 PM, jackster the jackle [email protected]
wrote:
** the problem I have now is with the tn.close command, the script times
out after the “show clock” command…any ideas?
yup, you are waiting for Username as a prompt now.
R.–
All truth passes through three stages. First, it is ridiculed. Second,
it is violently opposed. Third, it is accepted as being self-evident.
Schopenhauer (attr.)
thanks alot for the help from this forum…I was able to get into enable
mode and run a basic command with the following:
require ‘net/telnet’
CISCO = “172.30.152.1” #Enter the IP address here
USER = “username” #Enter username here
PASS = “password” #Enter password here
ENABLEPASS = “myenablepass”
SHOCLOCK = “show clock”
tn.cmd(“\n#{USER}”) { |c| print c }
tn.cmd(PASS) { |c| print c }
tn.print(“enable”) { |c| print c }
tn.print(“\n#{ENABLEPASS}”) { |c| print c }
tn.cmd(“\n#{SHOCLOCK}\n”) { |c| print c }
tn.close
** the problem I have now is with the tn.close command, the script times
out after the “show clock” command…any ideas?
thanks
jackster
Robert D. wrote:
On Dec 14, 2007 6:27 PM, jackster the jackle [email protected]
wrote:
“Timeout” => 5,
taking my password for some reason and I know the password is good.
tn.waitfor(/Password: /)
tn.cmd(ENABLE) { |c| print c }
tn.cmd “Match” => /Password[: ]*\z/, “String” => “enable”
works just fine on our catalysts, I am not exactly sure how waitfor
and cmd interact, but the Match parameter should do the trick.
All truth passes through three stages. First, it is ridiculed. Second,
it is violently opposed. Third, it is accepted as being self-evident.
Schopenhauer (attr.)
I once wrote this attached class to run cisco commands and fetch
configs. You
can run any command with the cmd method, like this will fetch and print
a
running config of a device:
I have narrowed down my problem to this. All my logins, passwords and
commands are running. When I run “show clock” at the enable prompt, my
logs show that the command is being run:
My problem is that the command $obj->cmd(“show clock”) hangs and times
out but only after it runs the command (according to the Net::Telnet
debug_log) and according to my tacacs accounting log on the server.
How do I get this to stop hanging and continue on to the next command in
my script?
thanks
jackster
Robert D. wrote:
On Dec 16, 2007 11:36 PM, jackster the jackle [email protected]
wrote:
** the problem I have now is with the tn.close command, the script times
out after the “show clock” command…any ideas?
yup, you are waiting for Username as a prompt now.
R.–
All truth passes through three stages. First, it is ridiculed. Second,
it is violently opposed. Third, it is accepted as being self-evident.
Schopenhauer (attr.)
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.