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. - use Net::Telnet;
-
use Term::ReadKey;
-
print "Enter username\n";
-
$user = <STDIN>;
-
chomp($user);
-
ReadMode( "noecho", STDIN );
-
print "Enter password\n";
-
$pwd = <STDIN>;
-
chomp($pwd);
-
ReadMode ("original", STDIN) ;
-
$epwd='pass';
-
$telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die');
-
$telnet->open('x.x.x.x');
-
$telnet->waitfor('/Username:/');
-
$telnet->print($user);
-
$telnet->waitfor('/Password:/');
-
$telnet->print($pwd);
-
-
sleep(1);
-
$telnet->print('en');
-
$telnet->waitfor('/Password:/');
-
$telnet->print($epwd);
-
-
sleep(1);
-
@lines=$telnet->print('sh ver | inc System serial');
-
sleep(1);
-
print @lines;
-
-
$telnet->close;
please suggest some solution
9 2886
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.
can you suggest changes in above program to get output insted of output 1
Use "cmd" method instead of "print".
I have tried "cmd" method instead of "print". but no change , it still gives output as 1 please help
RonB 589
Expert Mod 512MB
Try this version and then check the 2 log files. - #!/usr/bin/perl
-
-
use strict;
-
use warnings;
-
use Net::Telnet;
-
use Term::ReadKey;
-
-
print "Enter username\n";
-
chomp(my $user = <STDIN>);
-
-
ReadMode 'noecho';
-
print "Enter password\n";
-
chomp(my $pwd = <STDIN>);
-
ReadMode 'normal';
-
-
my $epwd = 'pass';
-
-
my $telnet = Net::Telnet->new(
-
Input_log => 'inputlog',
-
Dump_log => 'dumplog'
-
);
-
-
$telnet->open('x.x.x.x');
-
$telnet->waitfor('/Username:/');
-
$telnet->print($user);
-
$telnet->waitfor('/Password:/');
-
$telnet->print($pwd);
-
-
sleep(1);
-
$telnet->print('en');
-
$telnet->waitfor('/Password:/');
-
$telnet->print($epwd);
-
-
sleep(1);
-
my @lines = $telnet->cmd('sh ver | inc System serial');
-
sleep(1);
-
print @lines;
-
-
$telnet->close;
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
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.
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?
Hi,
it takes just 2 seconds before returning to command prompt ,
i am connecting to cisco 1841 router ant it supports a piped command
Sign in to post your reply or Sign up for a free account.
Similar topics
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:
-------------------------------------...
|
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...
|
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" ;
|
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 =...
|
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...
|
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....
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
|
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,...
| |