Help on Net::Telnet perl module

Help on Net::Telnet perl module

am 08.07.2011 14:59:25 von Irfan Sayed

--0-778832742-1310129965=:21091
Content-Type: text/plain; charset=us-ascii

hi,

i am using Net::Telnet module to connect to remote hosts
i able to to successfully connect to remote host and run the "ls" command
but the issue is , the output of command is not getting printed to scalar variable


use Net::Telnet ();
$t = new Net::Telnet (Timeout => 10,
Prompt => '/bash\$ $/');
$t->open("abc");
$t->login($username, $passwd);
@lines = $t->cmd("ls");
print @lines;

please suggest.

regards,
irfan
--0-778832742-1310129965=:21091--

Re: Help on Net::Telnet perl module

am 08.07.2011 19:13:37 von Jim Gibson

On 7/8/11 Fri Jul 8, 2011 5:59 AM, "Irfan Sayed"
scribbled:

> hi,
>
> i am using Net::Telnet module to connect to remote hosts
> i able to to successfully connect to remote host and run the "ls" command
> but the issue is , the output of command is not getting printed to scalar
> variable
>
>
> use Net::Telnet ();
> $t = new Net::Telnet (Timeout => 10,
> Prompt => '/bash\$ $/');
> $t->open("abc");
> $t->login($username, $passwd);
> @lines = $t->cmd("ls");
> print @lines;

That looks like the sample code included with 'perldoc Net::Telnet'. That
presumes that you have assigned valid values to the $username and $passwd
variables. Have you?

You have no error checking in your code. Since you are apparently getting an
error, it is time to add some error checking. See 'perldoc Net::Telnet' for
how to do this. The documentation recommends the use of input_log() and
dump_log() to trace the data sent back and forth between your program and
the telnet server.

Unfortunately, I cannot find a telnet server to test your program. Most
telnet access has been replaced by ssh these days.



--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Help on Net::Telnet perl module

am 08.07.2011 21:03:19 von Irfan Sayed

--0-2113045390-1310151799=:31307
Content-Type: text/plain; charset=us-ascii

i have written my own code and i am printing dump_log and input_log as well
in the log , it says , everything is successful, i am getting the output of "ls" command as well.in the log


but on the console it is not printing the output


plz suggest

regards
irfan



________________________________
From: Jim Gibson
To: Perl Beginners
Sent: Friday, July 8, 2011 10:47 PM
Subject: Re: Help on Net::Telnet perl module




You chose to allow Jim Gibson (jimsgibson@gmail.com) even though this message failed authentication
Click to disallow
--0-2113045390-1310151799=:31307--

Re: Help on Net::Telnet perl module

am 09.07.2011 00:37:44 von Jim Gibson

On 7/8/11 Fri Jul 8, 2011 12:43 PM, "Irfan Sayed"
scribbled:

> here is the actual code
>
>
> use Net::Telnet;
> $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die');
> $telnet->open('10.216.119.53');
> $telnet->waitfor('/login: $/i');
> $telnet->print('abc');
> $telnet->waitfor('/password: $/i');
> $telnet->print('xyz');
> $telnet->waitfor('/\$ $/i');
> $telnet->print('ls');
> $output = $telnet->waitfor('/\$ $/i');
> print $output;
>
>
> now, what i expect is, programme shud print the content of $output on the
> console
>
> the $output shud have the value of the result of "ls" command
>
> plz suggest

Please read the documentation for Net::Telnet, which says that the print
function returns 1 if all data was successfully written. If you wish to
capture the output from a command executed on the telnet server, use the
cmd() function and assign the function return to an array, not a scalar:

my @output = $telnet->cmd('ls');
print @output;




--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Help on Net::Telnet perl module

am 09.07.2011 20:46:12 von Irfan Sayed

--0-1231488205-1310237172=:66528
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

=A0modified the code. =A0 my $t =3D new Net::Telnet (Timeout =3D> 20,=
  =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Prompt =3D> '/bash\=
$ $/',   =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Dump_Log=A0 =
=3D> $filename,   =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Inpu=
t_log=A0 =3D> $file,   =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
Errmode=A0 =A0 =3D> $errmode,   =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 Host =3D> $host,   =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 Input_record_separator =3D> "\n",   =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 Output_record_separator =3D> "\n",=0A); =A0 =
=A0 $t->open("$host");   =A0 $t->login($username, $passwd); my @=
lines =3D $t->cmd("ls");   =A0 =A0 =A0 print "@lines\n";   =A0 my=
$ok =3D $t->print(@lines);   =A0 print "$ok\n"; in this code also=
, i am expecting @lines should print the contents =0Aof "ls" command=0Awhe=
n i execute this code , it just execute without any error but the cont=
ent of @lines are NULL=0Athe dump_log and input_log says , it has successfu=
lly connected to =0Aremote server and executed the "ls " command but @lines=
does not =0Acontain any output of "ls" command/ this is also not happ=
ening plz suggest =0A________________________________=0AFrom: Jim=
Gibson =0ATo: Irfan Sayed >; beginners@perl.org=0ASent: Saturday, July 9, 2011 4:08 AM=0ASubject: Re:=
Help on Net::Telnet perl module =0A You chose to allow Jim Gibs=
on (jimsgibson@gmail.com) even though this message failed authentication =
=0AClick to disallow
--0-1231488205-1310237172=:66528--

Re: Help on Net::Telnet perl module

am 11.07.2011 17:49:38 von John Mason Jr

On 7/9/2011 2:46 PM, Irfan Sayed wrote:
> modified the code.
>
> my $t = new Net::Telnet (Timeout => 20,
> Prompt => '/bash\$ $/',
> Dump_Log => $filename,
> Input_log => $file,
> Errmode => $errmode,
> Host => $host,
> Input_record_separator => "\n",
> Output_record_separator => "\n",
> );
>
> $t->open("$host");
> $t->login($username, $passwd);
>
> my @lines = $t->cmd("ls");
> print "@lines\n";
> my $ok = $t->print(@lines);
> print "$ok\n";
>
> in this code also , i am expecting @lines should print the contents
> of "ls" command
> when i execute this code , it just execute without any error
>
> but the content of @lines are NULL
> the dump_log and input_log says , it has successfully connected to
> remote server and executed the "ls " command but @lines does not
> contain any output of "ls" command/
>
> this is also not happening
>
> plz suggest
>
I have a suspicion that your prompt is not being matched, and then you
are timing out.

You may find that if you aren't seeing what you need to troubleshoot
this in the logs that using wiresharrk to capture the network traffic
might help.

http://www.wireshark.org/


John



--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/