473,468 Members | 1,358 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

getlines from Net::Telnet works different (works/does not work). while loop opt?

2 New Member
Hello.

I'm trying to work with Cisco hardware.

Simple script read the config:
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use Net::Telnet;
  6.  
  7. my $t;
  8. my $host = "megahw";
  9. my $username = "megauser";
  10. my $passwd = "megapassword";
  11. my @lines = ();
  12. my $fh;
  13. my $fn = "/var/tmp/t.log";
  14. my $lline;
  15. my @llines = ();
  16. my $ownline;
  17. my $screenlines;
  18.  
  19. $t = new Net::Telnet(Timeout => 10, Prompt => '/Username: $/');
  20. $t->open($host);
  21. $fh = $t->input_log($fn);
  22. $t->login(Name => $username, Password => $passwd, Prompt => '/#$/');
  23. $t->print("show running-config");
  24. @lines = ();
  25. $ownline = 1;
  26. $screenlines = 25;
  27.  
  28. while (1){
  29.     @llines = $t->getlines(All => 0);
  30.     $lline = scalar @llines;
  31.  
  32.     if ($lline == $screenlines){
  33.  
  34.         while (scalar @llines){
  35.             $lline = shift @llines;
  36.             push @lines, $lline;
  37.         }
  38.  
  39.         if ($ownline){
  40.             $ownline = 0;
  41.             $screenlines -= 2;
  42.         }
  43.  
  44.         $t->put(' ');
  45.         next;
  46.     }else{
  47.  
  48.         while (scalar @llines){
  49.             $lline = shift @llines;
  50.             push @lines, $lline;
  51.         }
  52.  
  53.         last;
  54.     }
  55.  
  56. }
  57.  
  58. $t->print("exit");
  59. $t->break;
  60. $t->close;
  61.  
  62. while (scalar @lines){
  63.     $lline = shift @lines;
  64.     print $lline;
  65. }
  66.  
If I run it flat (script.pl) I get my own command only. t.log has:
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. User Access Verification
  4.  
  5. Username: megauser
  6. Password: 
  7.  
  8. megahw#show running-config
  9.  
If I run it via perl -d script.pl and type c(ontinue) immediately the t.log is the same.

If I run it via perl -d script.pl and go inside while(1) loop via n(ext) commands and then c(continue), the t.log has:
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. User Access Verification
  4.  
  5. Username: megauser
  6. Password: 
  7.  
  8. megahw#show running-config
  9. Building configuration...
  10.  
  11. Current configuration : 2201 bytes
  12. !
  13. ! No configuration change since last restart
  14. !
  15. version 15.2
  16. no service pad
  17. service timestamps debug datetime msec
  18. service timestamps log datetime msec
  19. !
  20. hostname megahw
  21. !
  22. boot-start-marker
  23. !
  24. There are many lines of config
  25. !
  26. end
  27.  
That behaviour is very strange for me.

Any clues?
May 26 '16 #1
0 3846

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: cv | last post by:
Hello All, I have used MultipartRequest like the following to upload images. MultipartRequest multi = new MultipartRequest(request, "../webapps/coreprogram/dealerlogos", 1024 * 1024); It...
8
by: Peter Abel | last post by:
Hi all, I'm working under W2k with Python 2.2.2 (#37, Oct 14 2002, 17:02:34) on win32 I have a file *test_data.txt* with the following content: 0123456789 0123456789 abcdefghi...
3
by: F. GEIGER | last post by:
When I start a py2exe-ed application I get the error 'ascii' codec can't encode character u'\xe9' in position 10: ordinal not in range(128) This is how I run py2exe: setup.py py2exe -O1...
4
by: Das | last post by:
Hi, I have made an application in ASP.net with C#. The application works fine with localhost. I have uploaded the site. I'm using web user controls in the form. but some of the button do not work...
5
by: Trevor | last post by:
Why does alert(data); work fine while var subject = data; give me the error, "Error: data has no properties"? for (i = 0; i < (data.length); i++) { alert(data); //this works fine! var subject...
6
by: comp.lang.php | last post by:
I am using session_start() on index.php and for some reason sometimes it'll fail. No warnings, no errors, no notices, not even after prepending error_reporting(E_ALL) and ini_set('display_errors',...
0
by: henk-jan ebbers | last post by:
Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.9 Precedence: list List-Id: General discussion...
11
by: Jim | last post by:
Hi, I want to schedule a Python program that reads the command line for input. However, when adding an argument to the command line Python will not pick it up when using Windows scheduled...
10
by: nspader | last post by:
I am having trouble with my loop code. The code works very well. However, it only loops through 3 records and then completes without errors. I will post code below. Any help with this would be...
9
by: sceptar17 | last post by:
The code below is a part of a scheduling database that my department uses. The user is able to indicate a scheduling priority by request type (the records in FrmPrioritySheet) and then the code is to...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.