Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No output from telnet->cmd(´show mac´)

Status
Not open for further replies.

hanzonizer

Programmer
Joined
Apr 16, 2007
Messages
10
Location
SE
I´m trying to make a script that reads the mac-adress-table from a cisco 2610 router and then writes the data to a netdisco database. The problem is that I don´t get the command :
Code:
my @mac = $telnet->cmd(´show mac dynamic | begin 0´)
to work. The output thats supposed to be generated by the command and set to the list in @mac only shows when I watch the traffic with ethereal. when I try to print @mac it only returns null-values.
I have tried setting both telnet_mode and cmd_remove_mode to ones and zeros but with no luck.
Is there any way to trigger the cmd-command so that it generates the output, or do I need another solution?

Regards Jimmy
 
You want to do a "show arp", not a "show mac-address-table". If I'm not mistaken, unless you are bridging with your router, you won't have anything in your mac-address-table. You'd want to use "show mac-address-table" on a layer 2 device (i.e. a switch).
 
Maybe I was a little bit unclear in my explanation. The cisco 2610 router has a built in switch-port. That´s wy I need to use show mac instead of show arp. You can´t poll the mac-adresses from it via SMNP because of that fact. Anyhow, the telnet->cmd doesn´t output any data no matter if you run show arp or show mac.

Thanks for the comment anyway!, I appreciate any answers or comments that can help me forward.
 
Ah, I should paid more attention to the model number. When you type that command from the console, you do get output, correct?

Maybe you need to add a "return" in your script...I've seen this needed with some commands:

my @mac = $telnet->cmd(´show mac dynamic | begin 0\n´)

\n = return/enter
 
Yes, I get output when I type the command from the console. Unfortunatly the "return" didn´t do the trick. When I add it it doesn´t even recognize the command, so it must already be sending that in the end.

I have tried to have an telnet->waitfor(prompt) after the telnet->cmd and that did indeed do something good, cause when I look in the filedump that I specify when I run the script it contains all the data that supposed to be in the output-list but the list itself is empty. (when I try to print it) That must mean that the data is being sent, but not inserted in the cmd-outputlist. Is there any solution to this? I have tried to capture the data with ethereal, and indeed it sends all the data from the show mac but none of it reaches the @mac-list.
 
You should probably post some more info. Can you post the entire script? Are you using "use strict;" and running your script with the "#!/usr/bin/perl -w" to catch warnings?

How are you actually running the script? From the command line with: perl myscript.pl?

Have you tried removing the "my" (bad form, bit if you've got a short script with a single block, you can do this with no negative affect).
 
Ok, forget that. Here's a working script that I just ran and it printed the desired output to the console. If you're running this in CGI or something, you'll obviously have to port it into that, but in any case, this works:

Code:
#/usr/bin/perl -w
# usage: perl showmac.pl -h hostname -p password
use Getopt::Long;
GetOptions(
     "host=s"     =>     \$host,
     "password=s" =>     \$pass,
);

use Net::Telnet::Cisco;
  my $session = Net::Telnet::Cisco->new(Host => $host);
		$session->login('login', $pass); 
		@out = $session->cmd('show mac-add | begin 0');
		print "$host\n";
		print "\n @out";

It's run from the command line with a -h and -p switch for host and vty password, as indicated on the second line.
 
Aha, you´re using Telnet::Cisco! I don´t, unfortunately. (working with a prewritten code that was intended for cisco pix firewall) On the other hand, I came up with a other solution that does work, but involved printing the data (in scalar format) to a file, and from there reading it into a list. It did the trick too. I´m guessing the reason for my error is that I didn´t use Telnet::Cisco. I will try your solution, to see if it works for me too, tough.

Thanks a lot for the help!. I really appreciated it!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top