By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,374 Members | 1,939 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,374 IT Pros & Developers. It's quick & easy.

perl output

P: 14
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
Share this Question
Share on Google+
9 Replies


Expert
P: 80
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

P: 14
can you suggest changes in above program to get output insted of output 1
Nov 3 '09 #3

Expert
P: 80
Use "cmd" method instead of "print".
Nov 4 '09 #4

P: 14
I have tried "cmd" method instead of "print". but no change , it still gives output as 1 please help
Nov 13 '09 #5

Expert Mod 100+
P: 589
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

P: 14
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

Expert
P: 80
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

Expert Mod 100+
P: 589
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

P: 14
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

Post your reply

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