473,547 Members | 2,553 Online
Bytes | Software Development & Data Engineering Community
+ 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 3853

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

Similar topics

3
4054
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 works fine. But When a user accesses through Internet, this does not work.
8
2996
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 ABCDEFGHIJKLMNOPQ
3
2226
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 --packages encodings This is how the .po-file looks like:
4
2881
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 when they are clicked. One thing that I have found that they are nested user controls. which do not work. I'm unable to understand what is the...
5
1209
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 = data; //this gives error! var sender = data; var date = data; }
6
1960
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', TRUE) before session_start() do I see anything, it just plain dies. I used LiveHTTPHeaders to verify that I am getting a 200 OK response, thus...
0
1325
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 list for the Python programming language <python-list.python.org> List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>,...
11
3374
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 tasks. How do I get it to work? Thanks, Jim
10
3057
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 greatly appreciated. I am using Windows 2000 with Access 2000, sending email through Outlook 2000. Private Sub Form_Load() On Error GoTo...
9
2943
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 look at all the requests for the chosen point in time (underlying records in FrmAutoPrioritize) and prioritize them by assigning the appropriate...
0
7510
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7703
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7463
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7797
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6032
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3493
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3473
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1923
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 we have to send another system
1
1050
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.