[28869] in Perl-Users-Digest
Perl-Users Digest, Issue: 113 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 9 22:51:13 2007
Date: Fri, 9 Feb 2007 19:50:39 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 9 Feb 2007 Volume: 11 Number: 113
Today's topics:
Net::Telnet Error handling/trapping <nospam@example.com>
Re: Net::Telnet Error handling/trapping <m@rtij.nl.invlalid>
Re: Net::Telnet Error handling/trapping <DJStunks@gmail.com>
Re: Net::Telnet Error handling/trapping <nospam@example.com>
Re: Net::Telnet Error handling/trapping <nospam@example.com>
Re: Net::Telnet Error handling/trapping <jgibson@mail.arc.nasa.gov>
Re: Net::Telnet Error handling/trapping <DJStunks@gmail.com>
Re: Net::Telnet Error handling/trapping (NOSPAM)
Re: Net::Telnet Error handling/trapping sl123@netherlands.area
Re: Net::Telnet Error handling/trapping sl123@netherlands.area
Re: Net::Telnet Error handling/trapping <DJStunks@gmail.com>
Re: Net::Telnet Error handling/trapping <spamtrap@dot-app.org>
Re: Net::Telnet Error handling/trapping <spamtrap@dot-app.org>
net::telnet pm issue solaris.identity@gmail.com
Re: net::telnet pm issue <glex_no-spam@qwest-spam-no.invalid>
Re: net::telnet pm issue solaris.identity@gmail.com
Re: net::telnet pm issue <joe@inwap.com>
Re: net::telnet pm issue solaris.identity@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 05 Feb 2007 13:38:47 -0800
From: "Chris G." <nospam@example.com>
Subject: Net::Telnet Error handling/trapping
Message-Id: <45c7a3ee$0$97250$892e7fe2@authen.yellow.readfreenews.net>
I have a script that reads in a csv files, parses the data, and uses the
info to run down a list of IP addresses and make telnet connections to
them. I do this to automate the backing up of my Foundry switch
configurations. This works great until I have an error. When I have an
error at connect time, it catches the error and reports it, just like I
want. However, it doesn't recover from the error and never makes any
more connections to the other switches, even though it says it does.
Here is my (relevant) code:
use warnings;
use strict;
use Net::Telnet;
sub GetCF;
sub GetCF {
my $telnet;
$telnet = new Net::Telnet ( Timeout=>10,
Host=>$ip,
Errmode=>\&uhoh,
);
<skipping commands executed after the connection is established>
}
sub uhoh {
if ( $@ ne "") {
print ("$@\n");
} else {
print "Success\n";
}
}
------------------------------
Date: Mon, 5 Feb 2007 22:50:10 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Net::Telnet Error handling/trapping
Message-Id: <idlk94-0v6.ln1@news.rtij.nl>
On Mon, 05 Feb 2007 13:38:47 -0800, Chris G. wrote:
> I have a script that reads in a csv files, parses the data, and uses the
> info to run down a list of IP addresses and make telnet connections to
> them. I do this to automate the backing up of my Foundry switch
> configurations. This works great until I have an error. When I have an
> error at connect time, it catches the error and reports it, just like I
> want. However, it doesn't recover from the error and never makes any
> more connections to the other switches, even though it says it does.
I use rancid for this. Actually I use it to backup the configs, but when
it's installed, it's a great way to run commands on any of the installed
network devices. And obviously parse the results in Perl.
And I actually had bad experiences with Net::Telnet to access Cisco
routers. It would sometimes just act weird. Never got to the bottom of it
though.
HTH,
M4
------------------------------
Date: 5 Feb 2007 15:51:21 -0800
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: Net::Telnet Error handling/trapping
Message-Id: <1170719481.240701.168020@k78g2000cwa.googlegroups.com>
On Feb 5, 2:38 pm, "Chris G." <nos...@example.com> wrote:
> I have a script that reads in a csv files, parses the data, and uses the
> info to run down a list of IP addresses and make telnet connections to
> them. I do this to automate the backing up of my Foundry switch
> configurations. This works great until I have an error. When I have an
> error at connect time, it catches the error and reports it, just like I
> want. However, it doesn't recover from the error and never makes any
> more connections to the other switches, even though it says it does.
>
> Here is my (relevant) code:
>
> use warnings;
> use strict;
> use Net::Telnet;
>
> sub GetCF;
>
> sub GetCF {
> my $telnet;
> $telnet = new Net::Telnet ( Timeout=>10,
> Host=>$ip,
> Errmode=>\&uhoh,
> );
>
> <skipping commands executed after the connection is established>
>
> }
>
> sub uhoh {
> if ( $@ ne "") {
> print ("$@\n");
> } else {
> print "Success\n";
> }
>
> }
how about something like this:
#!/usr/bin/perl
use warnings;
use strict;
use Net::Telnet;
my $t = Net::Telnet->new( Timeout => 10,
Errmode => sub { warn $_[0] },
);
HOST:
while ( my ($user,$pass,$host) = split /[,\n]/, <DATA> ) {
$t->open( $host ) or next HOST;
$t->login( $user,$pass ) or next HOST;
# do something with $t telnet session
$t->close;
}
__DATA__
user1,pass1,host1.example.com
user2,pass2,host1.example.com
user1,pass1,host2.example.com
user2,pass2,host2.example.com
-jp
PS - in the future please post only complete scripts including sample
data. if this means you have to do a little extra work putting
together a good question, you will be the better for it :-)
------------------------------
Date: Tue, 06 Feb 2007 08:20:19 -0800
From: "Chris G." <nospam@example.com>
Subject: Re: Net::Telnet Error handling/trapping
Message-Id: <45c8aaca$0$97230$892e7fe2@authen.yellow.readfreenews.net>
DJ,
I would have posted the entire script, but it's >220 lines of code. Do
you really want all that code??? I will post it, if you want. I
understand the reasoning behind your request. I was just trying to save
some bandwidth for others.
DJ Stunks wrote:
> PS - in the future please post only complete scripts including sample
> data. if this means you have to do a little extra work putting
> together a good question, you will be the better for it :-)
>
------------------------------
Date: Tue, 06 Feb 2007 08:23:49 -0800
From: "Chris G." <nospam@example.com>
Subject: Re: Net::Telnet Error handling/trapping
Message-Id: <45c8ab9b$0$97230$892e7fe2@authen.yellow.readfreenews.net>
Hi,
I like this idea and see that I did not provide enough information. I
apologize. But, in what you have given me, this is a good start for
future thinking.
In the code below, you do the
$t->open( $host ) or next HOST;
If I use that, what happens to that current attempt to open the telnet
session? Does that just go away and the script continues? I will get
some more info and post it to help clarify why I ask.
Regards,
Chris
DJ Stunks wrote:
> how about something like this:
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> use Net::Telnet;
>
> my $t = Net::Telnet->new( Timeout => 10,
> Errmode => sub { warn $_[0] },
> );
>
> HOST:
> while ( my ($user,$pass,$host) = split /[,\n]/, <DATA> ) {
>
> $t->open( $host ) or next HOST;
> $t->login( $user,$pass ) or next HOST;
>
> # do something with $t telnet session
>
> $t->close;
> }
>
> __DATA__
> user1,pass1,host1.example.com
> user2,pass2,host1.example.com
> user1,pass1,host2.example.com
> user2,pass2,host2.example.com
>
> -jp
------------------------------
Date: Tue, 06 Feb 2007 09:45:15 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Net::Telnet Error handling/trapping
Message-Id: <060220070945159832%jgibson@mail.arc.nasa.gov>
In article <45c8aaca$0$97230$892e7fe2@authen.yellow.readfreenews.net>,
Chris G. <nospam@example.com> wrote:
[top-posting fixed]
> DJ Stunks wrote:
>
> > PS - in the future please post only complete scripts including sample
> > data. if this means you have to do a little extra work putting
> > together a good question, you will be the better for it :-)
> >
> DJ,
>
> I would have posted the entire script, but it's >220 lines of code. Do
> you really want all that code??? I will post it, if you want. I
> understand the reasoning behind your request. I was just trying to save
> some bandwidth for others.
>
Nobody here wants to read a 220-line program. The idea is to trim your
program down to the smallest one that still demonstrates your problem
and to one that people can run themselves. In the process of doing
that, your may find the problem yourself. If not, then you are
maximizing the probability that somebody else can help you.
And please not top-post. It makes it easier to follow the thread if you
put your responses after the text to which you are responding.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: 6 Feb 2007 13:00:35 -0800
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: Net::Telnet Error handling/trapping
Message-Id: <1170795634.912224.270210@v45g2000cwv.googlegroups.com>
On Feb 6, 9:23 am, "Chris G." <nos...@example.com> wrote:
> DJ Stunks wrote:
> > how about something like this:
>
> > #!/usr/bin/perl
>
> > use warnings;
> > use strict;
>
> > use Net::Telnet;
>
> > my $t = Net::Telnet->new( Timeout => 10,
> > Errmode => sub { warn $_[0] },
> > );
>
> > HOST:
> > while ( my ($user,$pass,$host) = split /[,\n]/, <DATA> ) {
>
> > $t->open( $host ) or next HOST;
> > $t->login( $user,$pass ) or next HOST;
>
> > # do something with $t telnet session
>
> > $t->close;
> > }
>
> > __DATA__
> > user1,pass1,host1.example.com
> > user2,pass2,host1.example.com
> > user1,pass1,host2.example.com
> > user2,pass2,host2.example.com
>
> In the code below, you do the
> $t->open( $host ) or next HOST;
>
> If I use that, what happens to that current attempt to open the telnet
> session? Does that just go away and the script continues? I will get
> some more info and post it to help clarify why I ask.
[top posting repaired]
ok, let's break it down. as the Net::Telnet docs indicate, the open()
method returns undef on failure. So if the open is unable to connect
to the host (no telnetd running on the host, host name not resolvable,
host not contactable, etc) the open command returns undef. Since
undef is a false value, Perl tries the right hand side of the
statement to see if it will evaluate to true. The second half of the
or is to give up on the remainder of the statements in the body of the
while loop and just go on to the next iteration (if there is one).
Hope that answers your question,
-jp
------------------------------
Date: Tue, 06 Feb 2007 14:45:25 -0600
From: "Mumia W. (NOSPAM)" <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: Net::Telnet Error handling/trapping
Message-Id: <eqaqqn$7j3$2@aioe.org>
On 02/06/2007 10:23 AM, Chris G. wrote:
> DJ Stunks wrote:
>> how about something like this:
>>
>> #!/usr/bin/perl
>>
>> use warnings;
>> use strict;
>>
>> use Net::Telnet;
>>
>> my $t = Net::Telnet->new( Timeout => 10,
>> Errmode => sub { warn $_[0] },
>> );
>>
>> HOST:
>> while ( my ($user,$pass,$host) = split /[,\n]/, <DATA> ) {
>>
>> $t->open( $host ) or next HOST;
>> $t->login( $user,$pass ) or next HOST;
>>
>> # do something with $t telnet session
>>
>> $t->close;
>> }
>>
>> __DATA__
>> user1,pass1,host1.example.com
>> user2,pass2,host1.example.com
>> user1,pass1,host2.example.com
>> user2,pass2,host2.example.com
>>
>> -jp
> Hi,
>
> I like this idea and see that I did not provide enough information. I
> apologize. But, in what you have given me, this is a good start for
> future thinking.
>
> In the code below, you do the
> $t->open( $host ) or next HOST;
>
> If I use that, what happens to that current attempt to open the telnet
> session? Does that just go away and the script continues?
Yes. If the open fails, the program ignores that host and moves to the
next host.
> I will get
> some more info and post it to help clarify why I ask.
>
> Regards,
>
> Chris
>
>
Please bottom-post your replies, like I am doing in this message, and
please read the posting guidelines for this newsgroup:
http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
--
Windows Vista and your freedom in conflict:
http://www.securityfocus.com/columnists/420/2
------------------------------
Date: Wed, 07 Feb 2007 07:59:00 -0800
From: sl123@netherlands.area
Subject: Re: Net::Telnet Error handling/trapping
Message-Id: <fntjs29osdfb29vqpagcjb5k7g5lnjp9gm@4ax.com>
On Tue, 06 Feb 2007 08:23:49 -0800, "Chris G." <nospam@example.com> wrote:
I might do a new Telnet before each open.
If you want to you could store the failures in the
first attempt for later, retrying on a progressive time schedule.
Its just a suggestion
###########
"First try" LOOP:
read the ip from file (or array)
{
- new Telnet
- try to open
- Fail? Call fail sub with ip and attempt number. Do next in loop.
# Comunnication
- Call comunication sub
- Fail? Call fail sub with ip and attempt number
- close Telnet session
- Log a sucessfull transaction with ip/datestamp
}
call retry loop sub
exit program (or fall through)
~~~~~~
Comunication sub
{
- return sucess or fail
}
Fail sub
{
- Increment a fail counter, make it a new hash key, store ip in value.
- Log a failure
}
Retry sub
{
- Set Max_time allowed (that you can live with, 8 hours say)
- Zero a sequence
- Zero a time_so_ far
Loop as long as time_so_far is under Max_time (allowed)
{
Loop as long as there is hash entryies
{
- new Telnet
- try to open
- Fail? next in loop
# Comunnication
- Call comunication sub
- Sucess? Delete hash entry. Log a sucessfull transaction with ip/datestamp
- close Telnet session
}
- Return if ip hash is empty
- set sleep_time = 2 ** sequence (or some progression)
- sleep for sleep_time
- add sleep_time to time_so_far
- time_so_far > Max_time? Log the remaining failures, then return.
- increment sequence
}
}
>Hi,
>
>I like this idea and see that I did not provide enough information. I
>apologize. But, in what you have given me, this is a good start for
>future thinking.
>
>In the code below, you do the
> $t->open( $host ) or next HOST;
>
>If I use that, what happens to that current attempt to open the telnet
>session? Does that just go away and the script continues? I will get
>some more info and post it to help clarify why I ask.
>
>Regards,
>
>Chris
>
>
>DJ Stunks wrote:
>> how about something like this:
>>
>> #!/usr/bin/perl
>>
>> use warnings;
>> use strict;
>>
>> use Net::Telnet;
>>
>> my $t = Net::Telnet->new( Timeout => 10,
>> Errmode => sub { warn $_[0] },
>> );
>>
>> HOST:
>> while ( my ($user,$pass,$host) = split /[,\n]/, <DATA> ) {
>>
>> $t->open( $host ) or next HOST;
>> $t->login( $user,$pass ) or next HOST;
>>
>> # do something with $t telnet session
>>
>> $t->close;
>> }
>>
>> __DATA__
>> user1,pass1,host1.example.com
>> user2,pass2,host1.example.com
>> user1,pass1,host2.example.com
>> user2,pass2,host2.example.com
>>
>> -jp
------------------------------
Date: Wed, 07 Feb 2007 08:18:26 -0800
From: sl123@netherlands.area
Subject: Re: Net::Telnet Error handling/trapping
Message-Id: <nqujs2ls87q1pba6po106o854fribs32a0@4ax.com>
On Wed, 07 Feb 2007 07:59:00 -0800, sl123@netherlands.area wrote:
>On Tue, 06 Feb 2007 08:23:49 -0800, "Chris G." <nospam@example.com> wrote:
>
>I might do a new Telnet before each open.
>If you want to you could store the failures in the
>first attempt for later, retrying on a progressive time schedule.
>Its just a suggestion
>
>###########
>
>"First try" LOOP:
>read the ip from file (or array)
>{
> - new Telnet
> - try to open
> - Fail? Call fail sub with ip and attempt number. Do next in loop.
> # Comunnication
> - Call comunication sub
> - Fail? Call fail sub with ip and attempt number
> - close Telnet session
> - Log a sucessfull transaction with ip/datestamp
>}
>call retry loop sub
>exit program (or fall through)
>
>~~~~~~
>
>Comunication sub
>{
> - return sucess or fail
>}
>
>Fail sub
>{
> - Increment a fail counter, make it a new hash key, store ip in value.
> - Log a failure
>}
>
>
>Retry sub
>{
> - Set Max_time allowed (that you can live with, 8 hours say)
> - Zero a sequence
> - Zero a time_so_ far
> Loop as long as time_so_far is under Max_time (allowed)
> {
> Loop as long as there is hash entryies
# ... Loop once through the hash
> {
> - new Telnet
> - try to open
> - Fail? next in loop
> # Comunnication
> - Call comunication sub
> - Sucess? Delete hash entry. Log a sucessfull transaction with ip/datestamp
> - close Telnet session
> }
> - Return if ip hash is empty
> - set sleep_time = 2 ** sequence (or some progression)
> - sleep for sleep_time
> - add sleep_time to time_so_far
# - time_so_far > Max_time? Log the remaining failures, then return.
> - increment sequence
> }
- Log the remaining failures
>}
>
>>Hi,
>>
>>I like this idea and see that I did not provide enough information. I
>>apologize. But, in what you have given me, this is a good start for
>>future thinking.
>>
>>In the code below, you do the
>> $t->open( $host ) or next HOST;
>>
>>If I use that, what happens to that current attempt to open the telnet
>>session? Does that just go away and the script continues? I will get
>>some more info and post it to help clarify why I ask.
>>
>>Regards,
>>
>>Chris
>>
>>
>>DJ Stunks wrote:
>>> how about something like this:
>>>
>>> #!/usr/bin/perl
>>>
>>> use warnings;
>>> use strict;
>>>
>>> use Net::Telnet;
>>>
>>> my $t = Net::Telnet->new( Timeout => 10,
>>> Errmode => sub { warn $_[0] },
>>> );
>>>
>>> HOST:
>>> while ( my ($user,$pass,$host) = split /[,\n]/, <DATA> ) {
>>>
>>> $t->open( $host ) or next HOST;
>>> $t->login( $user,$pass ) or next HOST;
>>>
>>> # do something with $t telnet session
>>>
>>> $t->close;
>>> }
>>>
>>> __DATA__
>>> user1,pass1,host1.example.com
>>> user2,pass2,host1.example.com
>>> user1,pass1,host2.example.com
>>> user2,pass2,host2.example.com
>>>
>>> -jp
------------------------------
Date: 6 Feb 2007 20:28:49 -0800
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: Net::Telnet Error handling/trapping
Message-Id: <1170822529.351820.132710@p10g2000cwp.googlegroups.com>
On Feb 7, 8:59 am, s...@netherlands.area wrote:
> On Tue, 06 Feb 2007 08:23:49 -0800, "Chris G." <nos...@example.com> wrote:
>
> I might do a new Telnet before each open.
> <snip spew>
Might you, robic? Why? Instantiating a new object each time
accomplishes nothing and wastes cycles.
-jp
------------------------------
Date: Wed, 07 Feb 2007 01:36:57 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Net::Telnet Error handling/trapping
Message-Id: <m2wt2uzd6e.fsf@Sherm-Pendleys-Computer.local>
"Chris G." <nospam@example.com> writes:
> I would have posted the entire script, but it's >220 lines of code. Do
> you really want all that code???
The guidelines suggest posting *a* complete script that demonstrates the
problem you're having. There are two reasons for this:
First and foremost, in the process of winnowing out the parts of the script
that aren't actually relevant to the problem, many people find that they've
actually found the solution. That's what DJ was talking about when he said
it might take a little extra effort, and why it might be better for you than
just dumping your whole original script here.
And second, no one's going to wade through 220+ lines to do step one for you,
so dumping it all here would be pointless anyway. :-)
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Wed, 07 Feb 2007 01:38:42 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Net::Telnet Error handling/trapping
Message-Id: <m2sldizd3h.fsf@Sherm-Pendleys-Computer.local>
"DJ Stunks" <DJStunks@gmail.com> writes:
> On Feb 7, 8:59 am, s...@netherlands.area wrote:
>> On Tue, 06 Feb 2007 08:23:49 -0800, "Chris G." <nos...@example.com> wrote:
>>
>> I might do a new Telnet before each open.
>> <snip spew>
>
> Might you, robic? Why? Instantiating a new object each time
> accomplishes nothing and wastes cycles.
Kind of like Robic0 himself... :-)
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: 9 Feb 2007 12:33:12 -0800
From: solaris.identity@gmail.com
Subject: net::telnet pm issue
Message-Id: <1171053192.098107.260910@k78g2000cwa.googlegroups.com>
Hi,
Not matter what RE I try in 'waitfor' function does not match the
"Password" prompt.
Here is the piece of code, from your example that I used
## 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,
-output_record_separator => "\r");
$ssh->dump_log('passwd.log');
## Login to remote host.
$ssh->waitfor(-match => '/.*password:.*/i',
-errmode => "return")
or die "problem connecting to host: ", $ssh->lastline
when I do a ssh from command line the prompt ends with
Password:
here are the last few line of dump_log
< 0x00000: 50 65 72 6d 69 73 73 69 6f 6e 20 64 65 6e 69 65
Permission denie
< 0x00010: 64 20 28 67 73 73 61 70 69 2d 6b 65 79 65 78 2c d
(gssapi-keyex.
< 0x00020: 67 73 73 61 70 69 2d 77 69 74 68 2d 6d 69 63 2c gssapi-
with-mic.
< 0x00030: 70 75 62 6c 69 63 6b 65 79 2c 6b 65 79 62 6f 61
publickey.keyboa
< 0x00040: 72 64 2d 69 6e 74 65 72 61 63 74 69 76 65 29 2e rd-
interactive).
< 0x00000: 0d 0d 0a ...
Thanks
------------------------------
Date: Fri, 09 Feb 2007 15:05:33 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: net::telnet pm issue
Message-Id: <45cce1df$0$10298$815e3792@news.qwest.net>
solaris.identity@gmail.com wrote:
> Hi,
>
> Not matter what RE I try in 'waitfor' function does not match the
> "Password" prompt.
>
>
> Here is the piece of code, from your example that I used
>
> ## Create a Net::Telnet object to perform I/O on ssh's tty.
> use Net::Telnet;
> $ssh = new Net::Telnet (-fhopen => $pty,
[...]
> when I do a ssh from command line the prompt ends with
>
> Password:
When running ssh, from the command line, it's not the
same as telnet'ing to the port. Try it.. telnet
to the port.
If you're going to use SSH, then use the appropriate module.
------------------------------
Date: 9 Feb 2007 13:17:48 -0800
From: solaris.identity@gmail.com
Subject: Re: net::telnet pm issue
Message-Id: <1171055868.282580.204290@h3g2000cwc.googlegroups.com>
> When running ssh, from the command line, it's not the
> same as telnet'ing to the port. Try it.. telnet
> to the port.
>
> If you're going to use SSH, then use the appropriate module.- Hide quoted text -
Sorry, I don't understand what you are saying, this method was taken
directly from Net::Telnet module doc.
Thanks
------------------------------
Date: Fri, 09 Feb 2007 13:26:38 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: net::telnet pm issue
Message-Id: <aKCdnbEkx5-NelHYnZ2dnUVZ_vGinZ2d@comcast.com>
solaris.identity@gmail.com wrote:
> Not matter what RE I try in 'waitfor' function does not match the
> "Password" prompt.
You're assuming that it comes over the socket.
> $ssh = new Net::Telnet (-fhopen => $pty,
>
> when I do a ssh from command line the prompt ends with
>
> Password:
With telnet, the "Password:" prompt comes over the socket from the telnetd server.
With ssh, the "Password:" prompt comes from the ssh client and is read
from /dev/tty, not STDIN.
What made you choose Net::Telnet versus Net::SSH ?
-Joe
------------------------------
Date: 9 Feb 2007 17:10:59 -0800
From: solaris.identity@gmail.com
Subject: Re: net::telnet pm issue
Message-Id: <1171069859.661913.326240@s48g2000cws.googlegroups.com>
On Feb 9, 4:26 pm, Joe Smith <j...@inwap.com> wrote:
> solaris.ident...@gmail.com wrote:
> > Not matter what RE I try in 'waitfor' function does not match the
> > "Password" prompt.
>
> You're assuming that it comes over the socket.
>
> > $ssh = new Net::Telnet (-fhopen => $pty,
>
> > when I do a ssh from command line the prompt ends with
>
> > Password:
>
> With telnet, the "Password:" prompt comes over the socket from the telnetd server.
> With ssh, the "Password:" prompt comes from the ssh client and is read
> from /dev/tty, not STDIN.
>
> What made you choose Net::Telnet versus Net::SSH ?
>
> -Joe
I took this straight out of Net::Telnet web page examples
http://search.cpan.org/~jrogers/Net-Telnet-3.03/lib/Net/Telnet.pm#AUTHOR
there was no particular reason for using Net::Telnet. I found what I
wanted to do with an example .
here it is
## Main program.
{
my ($pty, $ssh, @lines);
my $host = "changeme";
my $user = "changeme";
my $password = "changeme";
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,
-output_record_separator => "\r");
## Login to remote host.
$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::Pty ();
$pty = new IO::Pty
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
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 113
**************************************