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!

Net::Telnet works but where is the output?

Status
Not open for further replies.

InDenial

Technical User
Aug 1, 2003
191
NL
Hi all,

I hope someone can help me with this. I am writing a little script to do one task on about 500 switches (cat1900 enterprise edition software).

Using Win2000 machine running the scripts from a dos-box. Using activestate Active Perl 5.8.

Here is the script sofar:

Code:
use strict;
use Net::Telnet; 

my $telnet = new Net::Telnet ( Timeout=>5, 
Binmode=>1, 
Output_log=>'./fout', 
Input_log=>'./fin',
Option_log=>'./option',
Dump_Log=>'./dump', 
Errmode=>'die',
Prompt=>'/switchname#/');
 
#Open telnet connection

   $telnet->open('10.0.0.1'); 
   $telnet->waitfor('/Press any key to continue\./i'); 
   $telnet->print(''); 

#Login part 1 (menu)

   $telnet->print('K'); 
   $telnet->waitfor('/switchname>/i');

#Login part 2 (enable mode)

   $telnet->print('en');
   $telnet->waitfor('/Enter password:/i');
   $telnet->print('password');

#Execute some commands and print them on screen (?)

   my @lines = $telnet->cmd('show vtp');
   print @lines;
   $telnet->print('exit');

exit;

The above works because I can see it in the Dump_Log. It (although not quite readable) shows that it does what I wanted the script to do.

In the Output_Log I see what commands have been given. (the print and cmd lines)

I do not see anything in the Input_Log and I would love to see what happens on the screen.

My questions are..

1. Why am I not seeing anything in the Input_Log?
2. Is it possible to show what happens during the script on the screen so I can see it happen?

Thanks in advance,

InDenial

 
This looks interesting -- is that Cisco kit you have there?
ppm> install Net::Telnet
Searching for 'Net::Telnet' returned multiple results. Using 'search' instead...

Searching in Active Repositories
1. Net-Telnet [3.03] Interact with TELNET port or other TCP ports
2. Net-Telnet-Cisco [1.10] automate Cisco management
3. Net-Telnet-Netscreen [1.01] interact with a Netscreen firewall

A module specially for Cisco stuff....

But your problem, have you tried the input_log() function?

input_log - log all input

$fh = $obj->input_log;
$fh = $obj->input_log($fh);
$fh = $obj->input_log($filename);
This method starts or stops logging of input. This is useful when debugging. Also see dump_log(). Because most command interpreters echo back commands received, it's likely all your output will also be in this log. Note that input logging occurs after newline translation. See binmode() for details on newline translation.

If no argument is given, the log filehandle is returned. An empty string indicates logging is off.

To stop logging, use an empty string as an argument.

If an open filehandle is given, it is used for logging and returned. Otherwise, the argument is assumed to be the name of a file, the file is opened for logging and a filehandle to it is returned. If the file can't be opened for writing, the error mode action is performed.


Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
MikeLacey,

I am using the Net::Telnet. The one especially for cisco does not work for me (I think) because this Switch does not use username/password.

below info on how the login works:

Code:
Catalyst 1900 Management Console
Copyright (c) Cisco Systems, Inc.  1993-1999
All rights reserved.
Enterprise Edition Software
Model Number:          WS-C1924-EN
-------------------------------------------------

1 user(s) now active on Management Console.

        User Interface Menu

     [M] Menus
     [K] Command Line

Enter Selection:  K


      CLI session with the switch is open.
      To end the CLI session, enter [Exit].

switch>en
Enter password:  ******
switch#

as you can see in my script I am using the input_log and I do get the info I want in there but.. I want that info to show up in the screen(dos box) where I started the program.

After typing the above I wonder if I just could put something else instead of the $filename in $obj->input_log($filename)

hmm would it be that because I am using input_log with a filename that it puts everything in the file instead of sending it to the screen?

InDenial

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top