Click here to get back home

getting output of telnet from perl script

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
getting output of telnet from perl script kishore.konjeti 04-10-2006
Posted by kishore.konjeti on April 10, 2006, 5:35 am
Please log in for more thread options


hi all,
i had written a code to connect to unix server from Windows xp where i
installed perl.
i have to do with telnet. I think I am able to connect with unix
server. but i am not able to get out put from the server. i have tried
with 'ls' and 'who' commands. it is giving output
"connectedlogged inBefore ls".

The code is :
use Net::Telnet;


# instantiate a new CGI object
my $telnet = new Net::Telnet(Timeout => 10,
Errmode => 'die');


$telnet->open("servername") or die "hai $telnet->errmsg ";
print "connected";
$telnet->waitfor('/login: $/i');
$telnet->print("ixlourd") or die $telnet->errmsg;
$telnet->waitfor('/password: $/i');
$telnet->print("qwest1") or die $telnet->errmsg;
print "logged in";
$telnet->waitfor('/ixlourd\@e2epia2: $/');
print "Before ls";
$telnet->print('who');
$telnet->waitfor('/ixlourd\@e2epia2: $/');
#$output = $telnet->waitfor('/$ $/i');
print $output;
@lines=$telnet->print("ls") or die $telnet->errmsg;


print @lines;


OUTPUT:
"connectedlogged inBefore ls".


I have copied telnet.pm module from CPAN to perl directory. why it is
not giving any output of 'ls' . it is simply it is giving
"connectedlogged inBefore ls"
How can i make check whether it is connected to my unix server
successfully.


Posted by xemoth on April 11, 2006, 1:50 am
Please log in for more thread options



Don't have Net::Telnet here, but does it not have a debug option.

Debug=>Filename ??

Check perldoc Net::Telnet


Owen


Posted by kishore.konjeti on April 27, 2006, 1:43 pm
Please log in for more thread options


yes i am getting output of telnet in debug folder by specifiying in
input_log parameter while telnet object construction. It is showing
correctly.. but i am not able to print using print @lines.
the code is i have written like this
use warnings;
use Net::Telnet;
my $dumplog = "dumplog.txt";
my $outputlog = "outputlog.txt";
my $inputlog="inputlog.txt";
# instantiate a new CGI object
my $telnet = new Net::Telnet(Timeout => 10,
Errmode => 'die',
Dump_Log => "$dumplog",
                output_log => "$outputlog",
                input_log=>"$inputlog",

);
# perform a single print statement, with liberal use of the perl
# string concatenator "." and some CGI methods

$telnet->open("server");
$telnet->waitfor('/login: $/i');
#$telnet->output_record_separator("\n");
$telnet->print("ixlourd") ;
$telnet->waitfor('/password: $/i');
$telnet->print("qwest1") ;

$telnet->waitfor('/ixlourd\@e2epia2: $/') ;


print "Before ls\n";


@lines= $telnet->cmd("banner KISHORE");
sleep(5);

print @lines; # here i am getting timed out error.


Posted by DJ Stunks on April 27, 2006, 8:41 pm
Please log in for more thread options



kishore.konjeti@gmail.com wrote:
> yes i am getting output of telnet in debug folder by specifiying in
> input_log parameter while telnet object construction. It is showing
> correctly.. but i am not able to print using print @lines.
> the code is i have written like this
> use warnings;
> use Net::Telnet;
> my $dumplog = "dumplog.txt";
> my $outputlog = "outputlog.txt";
> my $inputlog="inputlog.txt";
> # instantiate a new CGI object
> my $telnet = new Net::Telnet(Timeout => 10,
> Errmode => 'die',
> Dump_Log => "$dumplog",
>                 output_log => "$outputlog",
>                 input_log=>"$inputlog",
>
> );
> # perform a single print statement, with liberal use of the perl
> # string concatenator "." and some CGI methods
>
> $telnet->open("server");
> $telnet->waitfor('/login: $/i');
> #$telnet->output_record_separator("\n");
> $telnet->print("ixlourd") ;
> $telnet->waitfor('/password: $/i');
> $telnet->print("qwest1") ;
>
> $telnet->waitfor('/ixlourd\@e2epia2: $/') ;
>
>
> print "Before ls\n";
>
>
> @lines= $telnet->cmd("banner KISHORE");
> sleep(5);
>
> print @lines; # here i am getting timed out error.

How can you be trying to use a module without reading the
documentation?

if you prompt is really 'ixlourd@e2epia2: ' then the default Prompt
won't work ((care of the documentation I know that The default Prompt
is '/[$%#>] $/')), so how do you expect cmd() to know when it's done
getting input?? It sits there waiting to see something it recognizes
until it times out.

Here's how I usually approach this kind of problem:
1) read module documentation
2) write script with frequent reference to module documentation and
examples therein
3) run script
4) when (not if) script does not do what I expected, re-read
documentation and debug

You may want to consider a similar approach.

-jp


Posted by kishore.konjeti on May 5, 2006, 7:49 am
Please log in for more thread options


I have red the document. can u briefly tell this.. that means.. wht r
the changes i have to do in my script..( waitfor is for waiting for a
specified text needs to appear then can i use sleep for a time. may for
2 or 3 sec..) ..insted of cmd will print command can i use for
executing any commands and getting output of it in a variable ... how
can i supress timed out warning..
-kish


Similar ThreadsPosted
getting output of telnet from perl April 6, 2006, 6:03 am
Net::Telnet - Problems using "script->waitfor" - HELP Needed November 26, 2005, 1:13 am
Template-Toolkit: Flushing Output or Incremental Output, how? September 13, 2007, 2:45 pm
How to handle input and output of a program executed by System function in perl July 18, 2004, 2:31 pm
Telnet from perl September 23, 2004, 2:12 pm
Net::Telnet not working with perl 5.8.5 November 15, 2005, 2:48 am
problem in telnet using perl December 27, 2007, 11:22 pm
Using Net::Telnet to connect to Perl server January 22, 2005, 12:57 am
How do you telnet from 1 host to another using Telnet Module December 21, 2005, 4:15 pm
Executables out of perl script? April 20, 2006, 7:30 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap