Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > I don't understand the Net::Telnet error

Reply
Thread Tools

I don't understand the Net::Telnet error

 
 
grocery_stocker
Guest
Posts: n/a
 
      02-22-2008
When I run the following on Linux Fedora Core 6

#!/usr/bin/perl
use warnings;
use strict;
use diagnostics;

{
my ($pty, $ssh, @lines);
my $host = "arbornet.org";
my $user = "cd";
my $password = "testme";
my $prompt = "/changeme:~> $/";
## Start ssh program.
$pty = &spawn("ssh", "-l", $user, $host); # spawn() defined below
## Create a Net::Telnet object to perform I/O on ssh's tty.
use Net::Telnet;
$ssh = new Net::Telnet (-fhopen => $pty,
-prompt => $prompt,
-telnetmode => 0,
-cmd_remove_mode => 1);

## Login to remote host.
#$ssh->open($host);
#$ssh->login($user, $pass);
$ssh->waitfor(-match => '/password: ?$/i', -errmode => "return")
or die "problem connecting to host: ", $ssh->lastline;
$ssh->print($password);
$ssh->waitfor(-match => $ssh->prompt, -errmode => "return")
or die "login failed: ", $ssh->lastline;

## Send command, get and print its output.
@lines = $ssh->cmd("who");
print @lines;

exit;
} # end main program

sub spawn {
my(@cmd) = @_;
my($pid, $pty, $tty, $tty_fd);

## Create a new pseudo terminal.
use IO:ty ();
$pty = new IO:ty or die $!;

## Execute the program in another process.
unless ($pid = fork) { # child process
die "problem spawning program: $!\n" unless defined $pid;

## Disassociate process from existing controlling terminal.
use POSIX ();
POSIX::setsid
or die "setsid failed: $!";

## Associate process with a new controlling
terminal.
$tty = $pty->slave;
$tty_fd = $tty->fileno;
close $pty;

## Make stdio use the new controlling terminal.
open STDIN, "<&$tty_fd" or die $!;
open STDOUT, ">&$tty_fd" or die $!;
open STDERR, ">&STDOUT" or die $!;
close $tty;

## Execute requested program.
exec @cmd
or die "problem executing $cmd[0]\n";
} # end child process
$pty;
} # end sub spawn


I get the following error message......
[cdalten@localhost ~]$ ./bot2.pl
Uncaught exception from user code:
problem connecting to host: Welcome to FreeBSD!
at ./bot2.pl line 24
[cdalten@localhost ~]$


The "Welcome to FreeBSD!" is part of the message on the remote server.
However, netstat shows that I'm conneced.

tcp 0 0 66.81.68.80:53169
69.39.89.95:22 ESTABLISHED


What is causing this error message and more to the point. How come the
"who" command doesn't get executed.
 
Reply With Quote
 
 
 
 
comp.llang.perl.moderated
Guest
Posts: n/a
 
      02-22-2008
On Feb 21, 6:28 pm, grocery_stocker <(E-Mail Removed)> wrote:
> When I run the following on Linux Fedora Core 6
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> use diagnostics;
>
> {
> my ($pty, $ssh, @lines);
> my $host = "arbornet.org";
> my $user = "cd";
> my $password = "testme";
> my $prompt = "/changeme:~> $/";
> ## Start ssh program.
> $pty = &spawn("ssh", "-l", $user, $host); # spawn() defined below
> ## Create a Net::Telnet object to perform I/O on ssh's tty.
> use Net::Telnet;
> $ssh = new Net::Telnet (-fhopen => $pty,
> -prompt => $prompt,
> -telnetmode => 0,
> -cmd_remove_mode => 1);
>
> ## Login to remote host.
> #$ssh->open($host);
> #$ssh->login($user, $pass);
> $ssh->waitfor(-match => '/password: ?$/i', -errmode => "return")
> or die "problem connecting to host: ", $ssh->lastline;
> $ssh->print($password);
> $ssh->waitfor(-match => $ssh->prompt, -errmode => "return")
> or die "login failed: ", $ssh->lastline;
>
> ## Send command, get and print its output.
> @lines = $ssh->cmd("who");
> print @lines;
>
> exit;
>
> } # end main program
>
> sub spawn {
> my(@cmd) = @_;
> my($pid, $pty, $tty, $tty_fd);
>
> ## Create a new pseudo terminal.
> use IO:ty ();
> $pty = new IO:ty or die $!;
>
> ## Execute the program in another process.
> unless ($pid = fork) { # child process
> die "problem spawning program: $!\n" unless defined $pid;
>
> ## Disassociate process from existing controlling terminal.
> use POSIX ();
> POSIX::setsid
> or die "setsid failed: $!";
>
> ## Associate process with a new controlling
> terminal.
> $tty = $pty->slave;
> $tty_fd = $tty->fileno;
> close $pty;
>
> ## Make stdio use the new controlling terminal.
> open STDIN, "<&$tty_fd" or die $!;
> open STDOUT, ">&$tty_fd" or die $!;
> open STDERR, ">&STDOUT" or die $!;
> close $tty;
>
> ## Execute requested program.
> exec @cmd
> or die "problem executing $cmd[0]\n";
> } # end child process
> $pty;
>
> } # end sub spawn
>
> I get the following error message......
> [cdalten@localhost ~]$ ./bot2.pl
> Uncaught exception from user code:
> problem connecting to host: Welcome to FreeBSD!
> at ./bot2.pl line 24
> [cdalten@localhost ~]$
>
> The "Welcome to FreeBSD!" is part of the message on the remote server.
> However, netstat shows that I'm conneced.
>
> tcp 0 0 66.81.68.80:53169
> 69.39.89.95:22 ESTABLISHED
>
> What is causing this error message and more to the point. How come the
> "who" command doesn't get executed.


Looks like there was a generic error message:

...waitfor(-match => '/password: ?$/i',
-errmode => "return")
or die "problem connecting to host: "

You can add errmsg() for additional detail:

or die "problem connecting to host: ",
$ssh->errmsg;

If the message is a 'pattern match timeout' for
instance, you may want to set Dump_Log and/or
Input_Log to see what's being sent from the
server.


--
Charles DeRykus
 
Reply With Quote
 
 
 
 
grocery_stocker
Guest
Posts: n/a
 
      02-23-2008
On Feb 22, 3:40 pm, "comp.llang.perl.moderated" <c...@blv-
sam-01.ca.boeing.com> wrote:
> On Feb 21, 6:28 pm, grocery_stocker <(E-Mail Removed)> wrote:
>
>
>
> > When I run the following on Linux Fedora Core 6

>
> > #!/usr/bin/perl
> > use warnings;
> > use strict;
> > use diagnostics;

>
> > {
> > my ($pty, $ssh, @lines);
> > my $host = "arbornet.org";
> > my $user = "cd";
> > my $password = "testme";
> > my $prompt = "/changeme:~> $/";
> > ## Start ssh program.
> > $pty = &spawn("ssh", "-l", $user, $host); # spawn() defined below
> > ## Create a Net::Telnet object to perform I/O on ssh's tty.
> > use Net::Telnet;
> > $ssh = new Net::Telnet (-fhopen => $pty,
> > -prompt => $prompt,
> > -telnetmode => 0,
> > -cmd_remove_mode => 1);

>
> > ## Login to remote host.
> > #$ssh->open($host);
> > #$ssh->login($user, $pass);
> > $ssh->waitfor(-match => '/password: ?$/i', -errmode => "return")
> > or die "problem connecting to host: ", $ssh->lastline;
> > $ssh->print($password);
> > $ssh->waitfor(-match => $ssh->prompt, -errmode => "return")
> > or die "login failed: ", $ssh->lastline;

>
> > ## Send command, get and print its output.
> > @lines = $ssh->cmd("who");
> > print @lines;

>
> > exit;

>
> > } # end main program

>
> > sub spawn {
> > my(@cmd) = @_;
> > my($pid, $pty, $tty, $tty_fd);

>
> > ## Create a new pseudo terminal.
> > use IO:ty ();
> > $pty = new IO:ty or die $!;

>
> > ## Execute the program in another process.
> > unless ($pid = fork) { # child process
> > die "problem spawning program: $!\n" unless defined $pid;

>
> > ## Disassociate process from existing controlling terminal.
> > use POSIX ();
> > POSIX::setsid
> > or die "setsid failed: $!";

>
> > ## Associate process with a new controlling
> > terminal.
> > $tty = $pty->slave;
> > $tty_fd = $tty->fileno;
> > close $pty;

>
> > ## Make stdio use the new controlling terminal.
> > open STDIN, "<&$tty_fd" or die $!;
> > open STDOUT, ">&$tty_fd" or die $!;
> > open STDERR, ">&STDOUT" or die $!;
> > close $tty;

>
> > ## Execute requested program.
> > exec @cmd
> > or die "problem executing $cmd[0]\n";
> > } # end child process
> > $pty;

>
> > } # end sub spawn

>
> > I get the following error message......
> > [cdalten@localhost ~]$ ./bot2.pl
> > Uncaught exception from user code:
> > problem connecting to host: Welcome to FreeBSD!
> > at ./bot2.pl line 24
> > [cdalten@localhost ~]$

>
> > The "Welcome to FreeBSD!" is part of the message on the remote server.
> > However, netstat shows that I'm conneced.

>
> > tcp 0 0 66.81.68.80:53169
> > 69.39.89.95:22 ESTABLISHED

>
> > What is causing this error message and more to the point. How come the
> > "who" command doesn't get executed.

>
> Looks like there was a generic error message:
>
> ...waitfor(-match => '/password: ?$/i',
> -errmode => "return")
> or die "problem connecting to host: "
>
> You can add errmsg() for additional detail:
>
> or die "problem connecting to host: ",
> $ssh->errmsg;
>
> If the message is a 'pattern match timeout' for
> instance, you may want to set Dump_Log and/or
> Input_Log to see what's being sent from the
> server.
>


I added errmsg() and when I ran the code, got the following

[cdalten@localhost ~]$ ./bot2.pl
Uncaught exception from user code:
problem connecting to host: pattern match timed-out at ./
bot2.pl line 24.
at ./bot2.pl line 24


What package does Dump_Log and Input_log belong to?

 
Reply With Quote
 
comp.llang.perl.moderated
Guest
Posts: n/a
 
      02-23-2008
On Feb 22, 5:12 pm, grocery_stocker <(E-Mail Removed)> wrote:
> On Feb 22, 3:40 pm, "comp.llang.perl.moderated" <c...@blv-
>....
> [cdalten@localhost ~]$ ./bot2.pl
> Uncaught exception from user code:
> problem connecting to host: pattern match timed-out at ./
> bot2.pl line 24.
> at ./bot2.pl line 24
>
> What package does Dump_Log and Input_log belong to?


perldoc Net::Telnet (see METHODS):

$obj = new Net::Telnet (
...
[Dump_Log => $filename,]
...
[Input_log => $file,]

--
Charles DeRykus
 
Reply With Quote
 
grocery_stocker
Guest
Posts: n/a
 
      02-23-2008
On Feb 22, 7:28 pm, "comp.llang.perl.moderated" <c...@blv-
sam-01.ca.boeing.com> wrote:
> On Feb 22, 5:12 pm, grocery_stocker <(E-Mail Removed)> wrote:
>
> > On Feb 22, 3:40 pm, "comp.llang.perl.moderated" <c...@blv-
> >....
> > [cdalten@localhost ~]$ ./bot2.pl
> > Uncaught exception from user code:
> > problem connecting to host: pattern match timed-out at ./
> > bot2.pl line 24.
> > at ./bot2.pl line 24

>
> > What package does Dump_Log and Input_log belong to?

>
> perldoc Net::Telnet (see METHODS):
>
> $obj = new Net::Telnet (
> ...
> [Dump_Log => $filename,]
> ...
> [Input_log => $file,]
>



I'm not seeing the possible error here

[cdalten@localhost ~]$ more input.txt
Last login: Sat Feb 23 18:19:13 2008 from 66-81-69-96.bay
Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994
The Regents of the University of California. All rights
reserved.

FreeBSD 6.3-PRERELEASE (MNET) #1: Tue Nov 6 16:13:56 EST 2007

Welcome to FreeBSD!
m-net%
[cdalten@localhost ~]$

[cdalten@localhost ~]$ more dump.txt
< 0x00000: 4c 61 73 74 20 6c 6f 67 69 6e 3a 20 53 61 74 20 Last
login: Sat
< 0x00010: 46 65 62 20 32 33 20 31 38 3a 31 39 3a 31 33 20 Feb 23
18:19:13
< 0x00020: 32 30 30 38 20 66 72 6f 6d 20 36 36 2d 38 31 2d 2008
from 66-81-
< 0x00030: 36 39 2d 39 36 2e 62 61 79 0d 0d 0a 43 6f 70 79
69-96.bay...Copy
< 0x00040: 72 69 67 68 74 20 28 63 29 20 31 39 38 30 2c 20 right
(c) 1980.
< 0x00050: 31 39 38 33 2c 20 31 39 38 36 2c 20 31 39 38 38 1983.
1986. 1988
< 0x00060: 2c 20 31 39 39 30 2c 20 31 39 39 31 2c 20 31 39 . 1990.
1991. 19
< 0x00070: 39 33 2c 20 31 39 39 34 0d 0a 09 54 68 65 20 52 93.
1994...The R
< 0x00080: 65 67 65 6e 74 73 20 6f 66 20 74 68 65 20 55 6e egents
of the Un
< 0x00090: 69 76 65 72 73 69 74 79 20 6f 66 20 43 61 6c 69
iversity of Cali
< 0x000a0: 66 6f 72 6e 69 61 2e 20 20 41 6c 6c 20 72 69 67
fornia. All rig
< 0x000b0: 68 74 73 20 72 65 73 65 72 76 65 64 2e 0d 0a 0d hts
reserved....
< 0x000c0: 0a 46 72 65 65 42 53 44 20 36 2e 33 2d 50 52
45 .FreeBSD 6.3-PRE
< 0x000d0: 52 45 4c 45 41 53 45 20 28 4d 4e 45 54 29 20 23 RELEASE
(MNET) #
< 0x000e0: 31 3a 20 54 75 65 20 4e 6f 76 20 20 36 20 31 36 1: Tue
Nov 6 16
< 0x000f0: 3a 31 33 3a 35 36 20 45 53 54 20 32 30 30 37 0d :13:56
EST 2007.
< 0x00100: 0a 0d 0a 57 65 6c 63 6f 6d 65 20 74 6f 20 46
72 ...Welcome to Fr
< 0x00110: 65 65 42 53 44 21 0d 0a
eeBSD!..

< 0x00000: 1b 5b 31 6d 1b 5b 37 6d 25 1b 5b 32 37 6d 1b 5b .[1m.[7m
%.[27m.[
< 0x00010: 31 6d 1b 5b 6d 0f 20 20 20 20 20 20 20 20 20 20 1m.
[m.
< 0x00020: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20
< 0x00030: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20
< 0x00040: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20
< 0x00050: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20
< 0x00060: 20 20 20 20 20 0d .

< 0x00000: 0d 1b 5b 6d 0f 1b 5b 32 37 6d 1b 5b 32 34 6d 1b ..[m..
[27m.[24m.
< 0x00010: 5b 4a 6d 2d 6e 65 74 25 20 1b 5b 4b [Jm-net
% .[K

[cdalten@localhost ~]$



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
an error on multi-source, but I can't understand... Neil VHDL 11 03-11-2010 03:15 PM
don't understand error m miller ASP .Net 4 09-08-2006 06:58 PM
Read all of this to understand how it works. then check around on otherRead all of this to understand how it works. then check around on other thelisa martin Computer Support 2 08-18-2005 06:40 AM
Error message I don't understand simon ASP .Net 1 12-05-2003 03:54 PM
Need help to understand this code error 'server error in /online application' Ketul Patel ASP .Net 1 11-29-2003 04:10 PM



Advertisments