473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

perl output

Hi all ,

I have written script to view some router output , my script executes successfuly , but does'nt show any output, why ?, it always shows output as 1.
Expand|Select|Wrap|Line Numbers
  1. use Net::Telnet;
  2. use Term::ReadKey;
  3. print "Enter username\n";
  4. $user = <STDIN>;
  5. chomp($user);
  6. ReadMode( "noecho", STDIN );
  7. print "Enter password\n";
  8. $pwd = <STDIN>;
  9. chomp($pwd);
  10. ReadMode ("original", STDIN) ;
  11.  $epwd='pass';
  12. $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die');
  13. $telnet->open('x.x.x.x');
  14. $telnet->waitfor('/Username:/');
  15. $telnet->print($user);
  16. $telnet->waitfor('/Password:/');
  17. $telnet->print($pwd);
  18.  
  19. sleep(1);
  20. $telnet->print('en');
  21. $telnet->waitfor('/Password:/');
  22. $telnet->print($epwd);
  23.  
  24. sleep(1);
  25.  @lines=$telnet->print('sh ver | inc System serial');
  26. sleep(1);
  27. print @lines;
  28.  
  29. $telnet->close;
please suggest some solution
Oct 29 '09 #1
9 2886
chorny
80 Expert
From documentation:

$ok = $obj->print(@list);

This method writes @list followed by the output_record_separator to the open object and returns 1 if all data was successfully written.


P.S. Also you can try "dump_log" method.
Oct 31 '09 #2
can you suggest changes in above program to get output insted of output 1
Nov 3 '09 #3
chorny
80 Expert
Use "cmd" method instead of "print".
Nov 4 '09 #4
I have tried "cmd" method instead of "print". but no change , it still gives output as 1 please help
Nov 13 '09 #5
RonB
589 Expert Mod 512MB
Try this version and then check the 2 log files.
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use Net::Telnet;
  6. use Term::ReadKey;
  7.  
  8. print "Enter username\n";
  9. chomp(my $user = <STDIN>);
  10.  
  11. ReadMode 'noecho';
  12. print "Enter password\n";
  13. chomp(my $pwd = <STDIN>);
  14. ReadMode 'normal';
  15.  
  16. my $epwd = 'pass';
  17.  
  18. my $telnet = Net::Telnet->new(
  19.                               Input_log => 'inputlog',
  20.                               Dump_log  => 'dumplog'
  21.                              );
  22.  
  23. $telnet->open('x.x.x.x');
  24. $telnet->waitfor('/Username:/');
  25. $telnet->print($user);
  26. $telnet->waitfor('/Password:/');
  27. $telnet->print($pwd);
  28.  
  29. sleep(1);
  30. $telnet->print('en');
  31. $telnet->waitfor('/Password:/');
  32. $telnet->print($epwd);
  33.  
  34. sleep(1);
  35. my @lines = $telnet->cmd('sh ver | inc System serial');
  36. sleep(1);
  37. print @lines;
  38.  
  39. $telnet->close;
Nov 13 '09 #6
I have tried above version , it gives error at line 35 and shows command_timeout at line 35 and not printing any output on monitor ,
but when i checked inputlog it shows proper output which includes username , password , banner and required output of router . i want only the result of line 35 in that file . please suggest changes
Nov 15 '09 #7
chorny
80 Expert
How long is 'sh ver | inc System serial' executed before returning to command prompt, if run directly?

->cmd method may receive some lines, but it waits for command to finish.
Nov 15 '09 #8
RonB
589 Expert Mod 512MB
What is the exact wording of the error?

What router (brand and model) are you connecting to?

What is the expected output of your command supposed to be?

Are you sure your router's cli supports (what appears to be) a piped command?
Nov 15 '09 #9
Hi,
it takes just 2 seconds before returning to command prompt ,
i am connecting to cisco 1841 router ant it supports a piped command
Nov 16 '09 #10

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

Similar topics

4
by: Mark Wilson CPU | last post by:
This must be easy, but I'm missing something... I want to execute a Perl script, and capture ALL its output into a PHP variable. Here are my 2 files: -------------------------------------...
46
by: Reinhold Birkenfeld | last post by:
Hello, another Perl/Python question: the subject says it all. Perl is going to change dramatically to become a more powerful and easier to (read|write) language. Is Python taking a similar...
3
by: bernd wegener | last post by:
Hello netties, I coded the following in perl: open(LOGFILE,">&STDOUT") ; if ( $ARGV ) { close(LOGFILE) ; open(LOGFILE,">> $ARGV") or die "Cannot open file $ARGV\n" ;
10
by: Hendry Taylor | last post by:
I wrote a perl script and tested it on windows and it works fine. I then moved it onto a solaris machine and now it says that there is a syntax error with the following line of code: $user1 =...
4
by: banz | last post by:
Hello I have a problem to resolve: I wrote a Perlscript which caches data from a server (local on my machine) I would like to have a other connection to a remote server but I don't know how to...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
2
by: Marty Meyers | last post by:
I have the following line in a php file: $msg= exec("perl $scriptPath/insert.pl $d $u $t 2>&1", $returnVal); Can someone explain the "2>&1" argument? Second problem, this same line of code...
1
by: newhaven_lad | last post by:
Please could someone help, I have a Perl cgi script which works perfectly when run in a dos prompt, it connects to a database on my laptop and inserts a record. But when I use the internet browser...
0
by: muraley | last post by:
Hi, This client-server script does bi-directional communication. Setup i used: The server script on windows 2003 server and the client on a linux machine. Since i faced issues in getting the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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,...
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...
0
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,...

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.