getting output of telnet from perl script

getting output of telnet from perl script

am 10.04.2006 11:35:43 von kishore.konjeti

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.

Re: getting output of telnet from perl script

am 11.04.2006 07:50:08 von xemoth

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

Debug=>Filename ??

Check perldoc Net::Telnet


Owen

Re: getting output of telnet from perl script

am 27.04.2006 19:43:50 von kishore.konjeti

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.

Re: getting output of telnet from perl script

am 28.04.2006 02:41:32 von Jake Peavy

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

Re: getting output of telnet from perl script

am 05.05.2006 13:49:09 von kishore.konjeti

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

Re: getting output of telnet from perl script

am 05.05.2006 14:55:57 von jurgenex

kishore.konjeti@gmail.com wrote:
> I have red the document.

What document? Documentation to some module? Which module are your talking
about?

> can u briefly tell this.. that means.. wht

What do you mean by "u"? I realize that English is not your native language,
but please make an effort to write readable text.

> r the changes i have to do in my script..

What do you mean by "r"? I realize that English is not your native language,
but please make an effort to write readable text.

What script? I don't see any script in your posting.

> ( waitfor is for waiting for
> a specified text needs to appear then can i use sleep for a time.

Are you asking a question or are you making a statement here? I really don't
understand.

> may
> for 2 or 3 sec..)

You know, newlines are not a scarce resource. Hitting the "enter" key every
now and then in the right places would improve the readability of your text
significantly. And I assume you want to be read, right?

> ..insted of cmd will print command can i use for

What the *$#%&$% ? What is that supposed to mean? "Instead of cmd will print
command can I use".
Sorry, my English parser fails to parse that sentence.

> executing any commands and getting output of it in a variable .

Are you looking for backticks by any chance? See also the documentation of
system().

> .. how
> can i supress timed out warning..

Perl does not generate timeout warnings. Check the documentation of whatever
tools happens to generate them.

jue