Connecting Tech Pros Worldwide Help | Site Map

perl output

Newbie
 
Join Date: Sep 2009
Posts: 14
#1: 3 Weeks Ago
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
Newbie
 
Join Date: Jan 2008
Location: Moldova
Posts: 7
#2: 3 Weeks Ago

re: perl output


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.
Newbie
 
Join Date: Sep 2009
Posts: 14
#3: 2 Weeks Ago

re: perl output


can you suggest changes in above program to get output insted of output 1
Newbie
 
Join Date: Jan 2008
Location: Moldova
Posts: 7
#4: 2 Weeks Ago

re: perl output


Use "cmd" method instead of "print".
Newbie
 
Join Date: Sep 2009
Posts: 14
#5: 1 Week Ago

re: perl output


I have tried "cmd" method instead of "print". but no change , it still gives output as 1 please help
Member
 
Join Date: Jun 2009
Posts: 54
#6: 1 Week Ago

re: perl output


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;
Newbie
 
Join Date: Sep 2009
Posts: 14
#7: 1 Week Ago

re: perl output


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
Newbie
 
Join Date: Jan 2008
Location: Moldova
Posts: 7
#8: 1 Week Ago

re: perl output


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.
Member
 
Join Date: Jun 2009
Posts: 54
#9: 1 Week Ago

re: perl output


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?
Newbie
 
Join Date: Sep 2009
Posts: 14
#10: 6 Days Ago

re: perl output


Hi,
it takes just 2 seconds before returning to command prompt ,
i am connecting to cisco 1841 router ant it supports a piped command
Reply