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
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 <contact@thirdorder.net> wrote:
Hi Ruby Forum,
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
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
tn.cmd("\n#{USER}") { |c| print c }
tn.cmd(PASS) { |c| print c }
tn.cmd("sh mod\n") { |c| print c }
Instead of sending the command "sh mod\n" as shown above, I want to get
into enable mode and send the command "sh run\n".
The problem is, I get to the password prompt but the router is not
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.
<snip>
HTH
Robert
···
On Dec 14, 2007 6:27 PM, jackster the jackle <contact@thirdorder.net> wrote:
---
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:
On Friday 14 December 2007 18:27:00 jackster the jackle wrote:
Hi Ruby Forum,
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
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 Dober wrote:
···
On Dec 14, 2007 6:27 PM, jackster the jackle <contact@thirdorder.net> > 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.
<snip>
---
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.)
On Dec 16, 2007 11:36 PM, jackster the jackle <contact@thirdorder.net> wrote:
** the problem I have now is with the tn.close command, the script times
out after the "show clock" command....any ideas?
---
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 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 Dober wrote:
···
On Dec 16, 2007 11:36 PM, jackster the jackle <contact@thirdorder.net> > 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.)