You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
(1) |
Oct
(1) |
Nov
(26) |
Dec
(7) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(5) |
Feb
(3) |
Mar
(11) |
Apr
(10) |
May
(2) |
Jun
(5) |
Jul
(13) |
Aug
(2) |
Sep
(3) |
Oct
(10) |
Nov
(18) |
Dec
(29) |
2002 |
Jan
(12) |
Feb
(14) |
Mar
(73) |
Apr
(28) |
May
(21) |
Jun
(39) |
Jul
(40) |
Aug
(42) |
Sep
(20) |
Oct
(4) |
Nov
(9) |
Dec
(18) |
2003 |
Jan
(2) |
Feb
(8) |
Mar
(6) |
Apr
(24) |
May
(24) |
Jun
(14) |
Jul
(16) |
Aug
(36) |
Sep
(34) |
Oct
(23) |
Nov
(4) |
Dec
(15) |
2004 |
Jan
(6) |
Feb
(13) |
Mar
(7) |
Apr
(5) |
May
(11) |
Jun
(5) |
Jul
(4) |
Aug
|
Sep
(2) |
Oct
(16) |
Nov
(4) |
Dec
(9) |
2005 |
Jan
(2) |
Feb
(1) |
Mar
(3) |
Apr
(10) |
May
(5) |
Jun
(13) |
Jul
(3) |
Aug
|
Sep
(7) |
Oct
(5) |
Nov
(1) |
Dec
(9) |
2006 |
Jan
|
Feb
(10) |
Mar
(22) |
Apr
(14) |
May
(5) |
Jun
(4) |
Jul
(19) |
Aug
(7) |
Sep
(16) |
Oct
(4) |
Nov
(1) |
Dec
(16) |
2007 |
Jan
(17) |
Feb
|
Mar
(35) |
Apr
(5) |
May
(20) |
Jun
(11) |
Jul
(33) |
Aug
(3) |
Sep
(2) |
Oct
(11) |
Nov
(23) |
Dec
(5) |
2008 |
Jan
(10) |
Feb
(9) |
Mar
|
Apr
(6) |
May
(8) |
Jun
(7) |
Jul
|
Aug
(3) |
Sep
(2) |
Oct
(1) |
Nov
|
Dec
(20) |
2009 |
Jan
(8) |
Feb
(8) |
Mar
(3) |
Apr
(8) |
May
(2) |
Jun
(11) |
Jul
(2) |
Aug
|
Sep
(3) |
Oct
(1) |
Nov
(7) |
Dec
(4) |
2010 |
Jan
(2) |
Feb
(1) |
Mar
(3) |
Apr
|
May
(2) |
Jun
(2) |
Jul
(7) |
Aug
(3) |
Sep
(7) |
Oct
(2) |
Nov
(1) |
Dec
(4) |
2011 |
Jan
(4) |
Feb
(5) |
Mar
|
Apr
(3) |
May
(2) |
Jun
|
Jul
(6) |
Aug
|
Sep
|
Oct
(6) |
Nov
|
Dec
|
2012 |
Jan
|
Feb
(1) |
Mar
|
Apr
(3) |
May
|
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
(5) |
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
(7) |
Sep
(2) |
Oct
|
Nov
|
Dec
|
2015 |
Jan
|
Feb
|
Mar
(30) |
Apr
(10) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2017 |
Jan
|
Feb
|
Mar
(12) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
(1) |
2018 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2022 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2024 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
From: John B. (Lists) <li...@jo...> - 2007-04-05 18:50:42
|
The qr/^($promptRE)/ in the code below only matches a prompt at the start of a line (which is what my application needs). You need to remove the ^ from below to match partial words like assword or login ^ogin = "ogin" at start of line. ogin = ogin anywhere in the string (no ^ anchor). Ronald's code definitely works here :-) J. > $spawn=Expect->spawn("ssh $username\@$host /downloads/test.ksh\n"); > my %Hash=(); > #$Hash{'yes'}='yes'; > $Hash{'ogin'}='siva'; > $Hash{'ssword'}='corvino'; > $Hash{'Name'}='siva'; # The values for the remote command - > /downloads/test.ksh > $Hash{'Age'}='22'; # The values for the remote command - > /downloads/test.ksh > my $promptRE = join("|", keys %Hash); > print "-- $promptRE ---"; > $spawn->expect(10, > [ > qr/^($promptRE)/, > sub { > $spawn = shift; > my $prompt = ($spawn->matchlist())[0]; > $spawn->send($args{$prompt}, "\n"); > exp_continue; > } > ], > ); |
From: cpsiva <cp...@ya...> - 2007-04-03 21:09:23
|
Hi Roland, I have another problem here. When I execute the following piece of code using ssh, the initial print message is not displayed; its directly going to the getc function and waiting for the user input first and prints the message. This is that code segment that need to be executed on the remote server. I can't modify this code because it's part of Oracle cloning script. #!/usr/bin/perl ## Asks for Apps password # print("Enter the APPS password [APPS]:\n"); ## This line is not coming when try to execute on remote machine using ssh my $key=""; my $PWD=""; while ($key ne "\n") { $key = getc(); $PWD = "$PWD" . "$key"; } chomp ( $PWD ); if ( $PWD eq "") { $PWD ="APPS"; } print "Password is - $PWD\n"; ============= Output of the script when I use ssh manually. [odba@odba downloads]$ ssh devap@odevap /home/devap/test.pl oracle Enter the APPS password [APPS]: ####This line should have first and wait for the user input Password is - oracle [odba@odba downloads]$ ============= If I execute the script on the remote machine, it works fine. But, not with ssh command. Because of this problem, I am not able to automate the cloning using Expect.pm. I have spent lot of time on this and finally I have use Telnet.pm with SSH to handle the automation. I find Expect more easier than Telnet. I am sure you will have a solution for this. Please let me know your feedback on this. Thanks for your help again, Siva. Roland Giersig wrote: > > set up public key authentication so ssh doesn't ask for the password. > also, set Expect::Exp_Internal=1 so you can see what gets received and > matched. > > hope this helps, > > roland > > On 3/28/07, cpsiva <cp...@ya...> wrote: >> >> Hi Roland, >> >> I tried using this method, but its not working for me. >> Could you pls tell me what is wrong with this code? >> >> I am actually working on automating Oracle cloning scripts remotely which >> will have many user prompts. >> >> ... >> $spawn=Expect->spawn("ssh $username\@$host /downloads/test.ksh\n"); >> my %Hash=(); >> #$Hash{'yes'}='yes'; >> $Hash{'ogin'}='siva'; >> $Hash{'ssword'}='corvino'; >> $Hash{'Name'}='siva'; # The values for the remote command - >> /downloads/test.ksh >> $Hash{'Age'}='22'; # The values for the remote command - >> /downloads/test.ksh >> my $promptRE = join("|", keys %Hash); >> print "-- $promptRE ---"; >> $spawn->expect(10, >> [ >> qr/^($promptRE)/, >> sub { >> $spawn = shift; >> my $prompt = ($spawn->matchlist())[0]; >> $spawn->send($args{$prompt}, "\n"); >> exp_continue; >> } >> ], >> ); >> --- >> [odba@odba downloads]$ perl ssh.pl odba siva corvino >> -- Age|ssword|Name|ogin ---siva@odba's password: >> ---------- >> HEre password is not getting passed and so are the remaining prompts . >> This is what I am getting when I run the script using ssh manually. >> ---------------------- >> [odba@odba downloads]$ ssh siva@odba /downloads/test.ksh >> ssh siva@odba /downloads/test.ksh >> siva@odba's password: >> Enter Name >> siva >> line 1 >> line 2 >> Enter Age 29 >> Your Name siva >> Your Age 29 >> [odba@odba downloads]$ >> ====================== >> >> Thanks for your help! >> -Siva >> >> Roland Giersig wrote: >> > >> > how about >> > >> > my $promptRE = join("|", keys %args); >> > >> > $exp->expect($timeout, >> > [ >> > qr/^($promptRE) /, >> > sub { >> > $self = shift; >> > my $prompt = ($self->matchlist())[0]; >> > $self ->send($args{$prompt}, "\n"); >> > exp_continue >> > } >> > ], >> > ); >> > >> > to use a list of responses in the hash to be able to handle multiple >> > occurances of the same prompt is left as an exercise to the reader... >> > :-) >> > >> > >> > On 3/20/07, John Bradshaw (Lists) <li...@jo...> wrote: >> >> Hi all, >> >> >> >> Trying to drive an interactive session with some telecomms kit. It's a >> >> very simple interface - it gives a series of fixed prompts to which >> the >> >> user enters a response, nothing fancy but quite tedious. >> >> >> >> I have a Perl hash with the prompts as keys and the responses as the >> >> hashed values. >> >> >> >> Example of a session... >> >> REQ NEW >> >> TYPE TIE >> >> CUST 0 >> >> ... >> >> where REQ, TYPE and CUST are the kit's prompts - always on a new line >> >> ending with a space. NEW, TIE and 0 are the corresponding responses. >> >> >> >> So the draft code is... >> >> >> >> $exp->expect($timeout, >> >> [ >> >> qr/^REQ /, >> >> sub { >> >> $self = shift; >> >> $self ->send($args{"REQ"}, "\n"); >> >> exp_continue >> >> } >> >> ], >> >> [ >> >> qr/^TYPE /, >> >> sub { >> >> $self = shift; >> >> $self ->send($args{"TYPE"}, "\n"); >> >> exp_continue; >> >> } >> >> ], >> >> [ >> >> qr/^CUST /, >> >> sub { >> >> $self = shift; >> >> $self ->send($args{"CUST"}, "\n"); >> >> exp_continue; >> >> } >> >> ], >> >> # Hundreds more patterns here... >> >> ... >> >> ... >> >> ); >> >> >> >> This works fine however I'd like to build the expect loop during >> >> execution using the %args hash as it's easier to add hash pairs than >> >> have to modify code when a new prompt appears. >> >> >> >> Is this supported with Expect.pm? If so, any hints on the best way to >> >> code this? >> >> >> >> Thanks, >> >> John. >> >> >> >> >> >> >> >> >> ------------------------------------------------------------------------- >> >> Take Surveys. Earn Cash. Influence the Future of IT >> >> Join SourceForge.net's Techsay panel and you'll get the chance to >> share >> >> your >> >> opinions on IT & business topics through brief surveys-and earn cash >> >> >> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV >> >> _______________________________________________ >> >> Expectperl-discuss mailing list >> >> Exp...@li... >> >> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >> >> >> > >> > >> ------------------------------------------------------------------------- >> > Take Surveys. Earn Cash. Influence the Future of IT >> > Join SourceForge.net's Techsay panel and you'll get the chance to share >> > your >> > opinions on IT & business topics through brief surveys-and earn cash >> > >> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV >> > _______________________________________________ >> > Expectperl-discuss mailing list >> > Exp...@li... >> > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >> > >> > >> >> -- >> View this message in context: >> http://www.nabble.com/Using-a-hash-to-store-prompts---responses--tf3430547.html#a9704604 >> Sent from the Perl - Expectperl-Discuss mailing list archive at >> Nabble.com. >> >> >> ------------------------------------------------------------------------- >> Take Surveys. Earn Cash. Influence the Future of IT >> Join SourceForge.net's Techsay panel and you'll get the chance to share >> your >> opinions on IT & business topics through brief surveys-and earn cash >> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV >> _______________________________________________ >> Expectperl-discuss mailing list >> Exp...@li... >> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >> > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > -- View this message in context: http://www.nabble.com/Using-a-hash-to-store-prompts---responses--tf3430547.html#a9826402 Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. |
From: Roland G. <rgi...@cp...> - 2007-03-28 15:53:39
|
set up public key authentication so ssh doesn't ask for the password. also, set Expect::Exp_Internal=1 so you can see what gets received and matched. hope this helps, roland On 3/28/07, cpsiva <cp...@ya...> wrote: > > Hi Roland, > > I tried using this method, but its not working for me. > Could you pls tell me what is wrong with this code? > > I am actually working on automating Oracle cloning scripts remotely which > will have many user prompts. > > ... > $spawn=Expect->spawn("ssh $username\@$host /downloads/test.ksh\n"); > my %Hash=(); > #$Hash{'yes'}='yes'; > $Hash{'ogin'}='siva'; > $Hash{'ssword'}='corvino'; > $Hash{'Name'}='siva'; # The values for the remote command - > /downloads/test.ksh > $Hash{'Age'}='22'; # The values for the remote command - > /downloads/test.ksh > my $promptRE = join("|", keys %Hash); > print "-- $promptRE ---"; > $spawn->expect(10, > [ > qr/^($promptRE)/, > sub { > $spawn = shift; > my $prompt = ($spawn->matchlist())[0]; > $spawn->send($args{$prompt}, "\n"); > exp_continue; > } > ], > ); > --- > [odba@odba downloads]$ perl ssh.pl odba siva corvino > -- Age|ssword|Name|ogin ---siva@odba's password: > ---------- > HEre password is not getting passed and so are the remaining prompts . > This is what I am getting when I run the script using ssh manually. > ---------------------- > [odba@odba downloads]$ ssh siva@odba /downloads/test.ksh > ssh siva@odba /downloads/test.ksh > siva@odba's password: > Enter Name > siva > line 1 > line 2 > Enter Age 29 > Your Name siva > Your Age 29 > [odba@odba downloads]$ > ====================== > > Thanks for your help! > -Siva > > Roland Giersig wrote: > > > > how about > > > > my $promptRE = join("|", keys %args); > > > > $exp->expect($timeout, > > [ > > qr/^($promptRE) /, > > sub { > > $self = shift; > > my $prompt = ($self->matchlist())[0]; > > $self ->send($args{$prompt}, "\n"); > > exp_continue > > } > > ], > > ); > > > > to use a list of responses in the hash to be able to handle multiple > > occurances of the same prompt is left as an exercise to the reader... > > :-) > > > > > > On 3/20/07, John Bradshaw (Lists) <li...@jo...> wrote: > >> Hi all, > >> > >> Trying to drive an interactive session with some telecomms kit. It's a > >> very simple interface - it gives a series of fixed prompts to which the > >> user enters a response, nothing fancy but quite tedious. > >> > >> I have a Perl hash with the prompts as keys and the responses as the > >> hashed values. > >> > >> Example of a session... > >> REQ NEW > >> TYPE TIE > >> CUST 0 > >> ... > >> where REQ, TYPE and CUST are the kit's prompts - always on a new line > >> ending with a space. NEW, TIE and 0 are the corresponding responses. > >> > >> So the draft code is... > >> > >> $exp->expect($timeout, > >> [ > >> qr/^REQ /, > >> sub { > >> $self = shift; > >> $self ->send($args{"REQ"}, "\n"); > >> exp_continue > >> } > >> ], > >> [ > >> qr/^TYPE /, > >> sub { > >> $self = shift; > >> $self ->send($args{"TYPE"}, "\n"); > >> exp_continue; > >> } > >> ], > >> [ > >> qr/^CUST /, > >> sub { > >> $self = shift; > >> $self ->send($args{"CUST"}, "\n"); > >> exp_continue; > >> } > >> ], > >> # Hundreds more patterns here... > >> ... > >> ... > >> ); > >> > >> This works fine however I'd like to build the expect loop during > >> execution using the %args hash as it's easier to add hash pairs than > >> have to modify code when a new prompt appears. > >> > >> Is this supported with Expect.pm? If so, any hints on the best way to > >> code this? > >> > >> Thanks, > >> John. > >> > >> > >> > >> ------------------------------------------------------------------------- > >> Take Surveys. Earn Cash. Influence the Future of IT > >> Join SourceForge.net's Techsay panel and you'll get the chance to share > >> your > >> opinions on IT & business topics through brief surveys-and earn cash > >> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > >> _______________________________________________ > >> Expectperl-discuss mailing list > >> Exp...@li... > >> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > >> > > > > ------------------------------------------------------------------------- > > Take Surveys. Earn Cash. Influence the Future of IT > > Join SourceForge.net's Techsay panel and you'll get the chance to share > > your > > opinions on IT & business topics through brief surveys-and earn cash > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > _______________________________________________ > > Expectperl-discuss mailing list > > Exp...@li... > > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > > > > > -- > View this message in context: http://www.nabble.com/Using-a-hash-to-store-prompts---responses--tf3430547.html#a9704604 > Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |
From: cpsiva <cp...@ya...> - 2007-03-28 01:47:42
|
Hi Roland, I tried using this method, but its not working for me. Could you pls tell me what is wrong with this code? I am actually working on automating Oracle cloning scripts remotely which will have many user prompts. ... $spawn=Expect->spawn("ssh $username\@$host /downloads/test.ksh\n"); my %Hash=(); #$Hash{'yes'}='yes'; $Hash{'ogin'}='siva'; $Hash{'ssword'}='corvino'; $Hash{'Name'}='siva'; # The values for the remote command - /downloads/test.ksh $Hash{'Age'}='22'; # The values for the remote command - /downloads/test.ksh my $promptRE = join("|", keys %Hash); print "-- $promptRE ---"; $spawn->expect(10, [ qr/^($promptRE)/, sub { $spawn = shift; my $prompt = ($spawn->matchlist())[0]; $spawn->send($args{$prompt}, "\n"); exp_continue; } ], ); --- [odba@odba downloads]$ perl ssh.pl odba siva corvino -- Age|ssword|Name|ogin ---siva@odba's password: ---------- HEre password is not getting passed and so are the remaining prompts . This is what I am getting when I run the script using ssh manually. ---------------------- [odba@odba downloads]$ ssh siva@odba /downloads/test.ksh ssh siva@odba /downloads/test.ksh siva@odba's password: Enter Name siva line 1 line 2 Enter Age 29 Your Name siva Your Age 29 [odba@odba downloads]$ ====================== Thanks for your help! -Siva Roland Giersig wrote: > > how about > > my $promptRE = join("|", keys %args); > > $exp->expect($timeout, > [ > qr/^($promptRE) /, > sub { > $self = shift; > my $prompt = ($self->matchlist())[0]; > $self ->send($args{$prompt}, "\n"); > exp_continue > } > ], > ); > > to use a list of responses in the hash to be able to handle multiple > occurances of the same prompt is left as an exercise to the reader... > :-) > > > On 3/20/07, John Bradshaw (Lists) <li...@jo...> wrote: >> Hi all, >> >> Trying to drive an interactive session with some telecomms kit. It's a >> very simple interface - it gives a series of fixed prompts to which the >> user enters a response, nothing fancy but quite tedious. >> >> I have a Perl hash with the prompts as keys and the responses as the >> hashed values. >> >> Example of a session... >> REQ NEW >> TYPE TIE >> CUST 0 >> ... >> where REQ, TYPE and CUST are the kit's prompts - always on a new line >> ending with a space. NEW, TIE and 0 are the corresponding responses. >> >> So the draft code is... >> >> $exp->expect($timeout, >> [ >> qr/^REQ /, >> sub { >> $self = shift; >> $self ->send($args{"REQ"}, "\n"); >> exp_continue >> } >> ], >> [ >> qr/^TYPE /, >> sub { >> $self = shift; >> $self ->send($args{"TYPE"}, "\n"); >> exp_continue; >> } >> ], >> [ >> qr/^CUST /, >> sub { >> $self = shift; >> $self ->send($args{"CUST"}, "\n"); >> exp_continue; >> } >> ], >> # Hundreds more patterns here... >> ... >> ... >> ); >> >> This works fine however I'd like to build the expect loop during >> execution using the %args hash as it's easier to add hash pairs than >> have to modify code when a new prompt appears. >> >> Is this supported with Expect.pm? If so, any hints on the best way to >> code this? >> >> Thanks, >> John. >> >> >> >> ------------------------------------------------------------------------- >> Take Surveys. Earn Cash. Influence the Future of IT >> Join SourceForge.net's Techsay panel and you'll get the chance to share >> your >> opinions on IT & business topics through brief surveys-and earn cash >> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV >> _______________________________________________ >> Expectperl-discuss mailing list >> Exp...@li... >> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >> > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > -- View this message in context: http://www.nabble.com/Using-a-hash-to-store-prompts---responses--tf3430547.html#a9704604 Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. |
From: Stefaan C. <ste...@ax...> - 2007-03-24 19:34:15
|
On Saturday 24 March 2007, Ken Irving wrote: > On Thu, Mar 22, 2007 at 03:26:49PM +0100, Stefaan Coene wrote: > > Hi, > > > > I want to automate some remote commands and to do so, I want to match the > > prompt of the remote server. The problem is that there is a tilde (~) in > > the > > prompt. No mather what I tried, I can not match the prompt. > > Changing the prompt so there is no tilde in it, is no option. > > > > Any idea ? > > I don't think tilde should have any special meaning in regular > expressions, but it is sometimes used as an escape character in > transport protocols, e.g., ssh or the cu/tip program. If that's > where it's hanging up, it may be possible to specify a different > escape character, so tilde would work like an ordinary character. > Or, it's usually possible to "escape" an escape character, e.g,. > by using two of them instead of one. Just a guess. > > Ken I don't know that this messsage will reach the list. I tried to subscribe with different email address. Sometimes I got a confirmation email, sometimes I gog http errrors and so on. So I hope I didn't spammed the list too much. Anyway, when I set the prompt so there was no tilde in, expect is working like expected. The tilde was the problem. Was. I found a simple solution. When I spawn the remote session, I let it timeout and set the prompt to a random string. So, I can match the random string and don't have to match the ~ Stef |
From: Ken I. <fn...@ua...> - 2007-03-24 18:46:22
|
On Thu, Mar 22, 2007 at 03:26:49PM +0100, Stefaan Coene wrote: > Hi, > > I want to automate some remote commands and to do so, I want to match the > prompt of the remote server. The problem is that there is a tilde (~) in > the > prompt. No mather what I tried, I can not match the prompt. > Changing the prompt so there is no tilde in it, is no option. > > Any idea ? I don't think tilde should have any special meaning in regular expressions, but it is sometimes used as an escape character in transport protocols, e.g., ssh or the cu/tip program. If that's where it's hanging up, it may be possible to specify a different escape character, so tilde would work like an ordinary character. Or, it's usually possible to "escape" an escape character, e.g,. by using two of them instead of one. Just a guess. Ken -- Ken Irving, fn...@ua... |
From: Matt Z. <mzagrabe@d.umn.edu> - 2007-03-22 18:26:55
|
> The reason I am concerned with using Net::Telnet with Expect is I have > designed my program to be multithreaded and from what I read Net::Telnet > is thread safe whereas IO-Tty is not. >=20 > The symptoms of what happens when using Expect and Net::Telnet to telnet > to a 1924 is this: >=20 > telnet negotiation (non printable characters) happens and then it looks > like no other traffic is sent from the remote side. I am currently > combing through tcpdump and wireshark analysis of this, but I thought I > would send an email to the list to see if anyone had any ideas in the > meantime. Solved... All thanks goes to Bryan Bueter who did all the leg-work on this one. As he said (off list), Net::Telnet needed to be coaxed into getting past the telnet handshaking and negotiations, then it could be passed to Expect. The important line to note below is the 'waitfor'. Then it is safe to hand the file handle over to Expect. Working code follows: #!/usr/bin/perl use strict; use Expect; use Net::Telnet (); print "\n\n-----------START OF Expect with Net::Telnet-----------\n"; my $e =3D new Net::Telnet(); $e->open("c1924.domain.org"); my @lines =3D $e->waitfor('/User Interface Menu/'); my $exp =3D Expect->exp_init($e); $exp->log_stdout(1); &expect_selection($exp); $exp->expect(5,'-re','>\z'); $exp->hard_close(); print "\n\n-----------END OF Expect with Net::Telnet-----------\n"; sub expect_selection { my $exp =3D shift; $exp->expect(5, [ qr/Selection.*/, sub { my $fh =3D shift; $fh->send('k'); undef; } ]); } --=20 Matt Zagrabelny - mzagrabe@d.umn.edu - (218) 726 8844 University of Minnesota Duluth Information Technology Systems & Services PGP key 1024D/84E22DA2 2005-11-07 Fingerprint: 78F9 18B3 EF58 56F5 FC85 C5CA 53E7 887F 84E2 2DA2 He is not a fool who gives up what he cannot keep to gain what he cannot lose. -Jim Elliot |
From: Stefaan C. <ste...@ax...> - 2007-03-22 14:27:08
|
Hi, I want to automate some remote commands and to do so, I want to match the prompt of the remote server. The problem is that there is a tilde (~) in the prompt. No mather what I tried, I can not match the prompt. Changing the prompt so there is no tilde in it, is no option. Any idea ? Stef |
From: Bryan B. <br...@bu...> - 2007-03-21 20:30:22
|
> Hello, > > I am experiencing some strange behavior when combining Expect with > Net::Telnet when telnet'ing to Cisco 1924 switches. > > Scenario: > > Cisco Gear > > 1924's newer than 1924's > +----------+---------------------+ > Net::Telnet | works | works | > Expect spawning system telnet | works | works | > Expect using Net::Telnet | no work | works | > +----------+---------------------+ > > The reason I am concerned with using Net::Telnet with Expect is I have > designed my program to be multithreaded and from what I read Net::Telnet > is thread safe whereas IO-Tty is not. > I have used threading with expect on top of Net::Telnet successfully. Spawning a system telnet will, obviously, not work. > The symptoms of what happens when using Expect and Net::Telnet to telnet > to a 1924 is this: > > telnet negotiation (non printable characters) happens and then it looks > like no other traffic is sent from the remote side. I am currently > combing through tcpdump and wireshark analysis of this, but I thought I > would send an email to the list to see if anyone had any ideas in the > meantime. > > Here is some code that demonstrates what is happening: > #!/usr/bin/perl > > use strict; > use Expect; > use Net::Telnet (); > > print "\n\n-----------START OF Net::Telnet-----------\n"; > > my $t = new Net::Telnet("ghAS1.d.umn.edu"); > my @lines = $t->waitfor('/Selection.*/'); > print "@lines\n"; > > print "\n\n-----------END OF Net::Telnet-----------\n"; > print "\n\n-----------START OF Expect with Net::Telnet-----------\n"; > > my $e = new Net::Telnet("ghAS1.d.umn.edu"); > my $exp = Expect->exp_init($e); > $exp->log_stdout(1); > &expect_selection($exp); > Try this bit of code: -- snip --> my $e = new Net::Telnet(Prompt => '/Selection.*/'); $e->open("ghAS1.d.umn.edu"); my $exp = Expect->exp_init($e); $exp->log_stdout(1); &expect_selection($exp); <-- end -- The open() method should finish the handshaking for you. Also, if you have to log in, it might help to do that within the Net::Telnet object prior to expecting on top: $e->login($user, $password); Hope that helps. Bryan http://sourceforge.net/projects/rover |
From: Matt Z. <mzagrabe@d.umn.edu> - 2007-03-21 18:55:10
|
Hello, I am experiencing some strange behavior when combining Expect with Net::Telnet when telnet'ing to Cisco 1924 switches. Scenario: Cisco Gear 1924's newer than 1924's +----------+---------------------+ Net::Telnet | works | works | Expect spawning system telnet | works | works | Expect using Net::Telnet | no work | works | +----------+---------------------+ The reason I am concerned with using Net::Telnet with Expect is I have designed my program to be multithreaded and from what I read Net::Telnet is thread safe whereas IO-Tty is not. The symptoms of what happens when using Expect and Net::Telnet to telnet to a 1924 is this: telnet negotiation (non printable characters) happens and then it looks like no other traffic is sent from the remote side. I am currently combing through tcpdump and wireshark analysis of this, but I thought I would send an email to the list to see if anyone had any ideas in the meantime. Here is some code that demonstrates what is happening: #!/usr/bin/perl use strict; use Expect; use Net::Telnet (); print "\n\n-----------START OF Net::Telnet-----------\n"; my $t =3D new Net::Telnet("ghAS1.d.umn.edu"); my @lines =3D $t->waitfor('/Selection.*/'); print "@lines\n"; print "\n\n-----------END OF Net::Telnet-----------\n"; print "\n\n-----------START OF Expect with Net::Telnet-----------\n"; my $e =3D new Net::Telnet("ghAS1.d.umn.edu"); my $exp =3D Expect->exp_init($e); $exp->log_stdout(1); &expect_selection($exp); print "\n\n-----------END OF Expect with Net::Telnet-----------\n"; print "\n\n-----------START OF Expect with system telnet-----------\n"; my $exp =3D Expect->spawn("telnet ghAS1.d.umn.edu"); $exp->log_stdout(1); &expect_selection($exp); print "\n\n-----------END OF Expect with system telnet-----------\n"; sub expect_selection { my $exp =3D shift; $exp->expect(5, [ qr/Selection.*/, sub { my $fh =3D shift; $fh->send('k'); undef; } ]); } # end of code output from the code follows: -----------START OF Net::Telnet----------- Catalyst 1900 Management Console Copyright (c) Cisco Systems, Inc. 1993-1999 All rights reserved. Enterprise Edition Software Ethernet Address: 00-10-F6-24-A8-40 PCA Number: 73-2239-03 PCA Serial Number: SAD01452031 Model Number: WS-C1924-EN System Serial Number: FAA0148Z051 ------------------------------------------------- 3 user(s) now active on Management Console. User Interface Menu [M] Menus [K] Command Line Enter Selection: -----------END OF Net::Telnet----------- -----------START OF Expect with Net::Telnet----------- =EF=BF=BD=EF=BF=BD=03=EF=BF=BD=EF=BF=BD=03=EF=BF=BD -----------END OF Expect with Net::Telnet----------- -----------START OF Expect with system telnet----------- Trying 10.0.0.1 Will send login name and/or authentication information. Connected to c1924.domain.org (10.0.0.1). Escape character is '^]'. Catalyst 1900 Management Console Copyright (c) Cisco Systems, Inc. 1993-1999 All rights reserved. Enterprise Edition Software Ethernet Address: 00-10-F6-24-A8-40 PCA Number: 73-2239-03 PCA Serial Number: SAD01452031 Model Number: WS-C1924-EN System Serial Number: FAA0148Z051 ------------------------------------------------- 5 user(s) now active on Management Console. User Interface Menu [M] Menus [K] Command Line Enter Selection: -----------END OF Expect with system telnet----------- --=20 Matt Zagrabelny - mzagrabe@d.umn.edu - (218) 726 8844 University of Minnesota Duluth Information Technology Systems & Services PGP key 1024D/84E22DA2 2005-11-07 Fingerprint: 78F9 18B3 EF58 56F5 FC85 C5CA 53E7 887F 84E2 2DA2 He is not a fool who gives up what he cannot keep to gain what he cannot lose. -Jim Elliot |
From: Vladimir K. <ma...@ma...> - 2007-03-21 11:04:54
|
Hello, I have same problem, Expect not working in custom environment, probably because of stdin, stdout redirections. I'm using mod_perl, and simple expect scenario works perfect in shell and not at all in mod_perl i'm trying to connect server side and do some data exchange. server: while :; do nc -l -p333 -c'echo READY; read RESP; echo READY2; sleep 10'; echo Exited; done (listening at 333 port, sending READY on connect and READY2 on first line receive) my script: use Expect; my $myhandle = new Expect; $myhandle->log_user(0); $myhandle->spawn("nc 192.168.1.11 333"); $myhandle->expect(10, [ timeout => sub { print STDERR "timeout\n" } ], [ eof => sub { print STDERR "eof\n" } ], [ qr/READY[\r\n]+/ => sub { print STDERR "READY\n" } ], ); $myhandle->send("TEST\n"); $myhandle->expect(10, [ timeout => sub { print STDERR "timeout\n" } ], [ eof => sub { print STDERR "eof\n" } ], [ qr/READY2[\r\n]+ => sub { print STDERR "READY2\n" } ], ); from shell it shows: READY READY2 from mod_perl it shows: READY timeout so it hanging just after first data sent to server :( Bryan Cox wrote: > > Brad and Austin, > > I've finally figured this thing out (sort of). Expect works fine in a > "normal" environment. > > We have a utility built in-house that we use to log the output of our > scripts. That utility does some forking, redirection of stdin & stdout, > and unbuffering before I make my Expect call. Between the two modules, > there's just one too many redirects or something. I'm not sure if I'll > ever get it sorted out to the point where I can make them work together, > but they work fine independently. > > I've appreciated your help, and hope I can return the favor some time. > > Bryan > > -- View this message in context: http://www.nabble.com/Expect.pm---sftp-tf3398274.html#a9591652 Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. |
From: Bryan C. <co...@od...> - 2007-03-20 18:43:33
|
Brad and Austin, =20 I've finally figured this thing out (sort of). Expect works fine in a "normal" environment. =20 We have a utility built in-house that we use to log the output of our scripts. That utility does some forking, redirection of stdin & stdout, and unbuffering before I make my Expect call. Between the two modules, there's just one too many redirects or something. I'm not sure if I'll ever get it sorted out to the point where I can make them work together, but they work fine independently. =20 I've appreciated your help, and hope I can return the favor some time. =20 Bryan ________________________________ From: btr...@gm... [mailto:btr...@gm...] On Behalf Of Bradford Ritchie Sent: Thursday, March 15, 2007 9:07 PM To: Bryan Cox Cc: exp...@li... Subject: Re: [Expectperl-discuss] Expect.pm & sftp Bryan, Looking at your code more closely, have you tried replacing qr/$_sftp_prompt/ with a literal string like qr/myprompt%/ or 'myprompt' ? Might be worth a try since the other two expect lines seem to be succeeding for you. =20 Also, not that it matters, but I noticed that in sub that handles the password, you define $exp_self to hold the expect object instance, but then call $self->verbose(). Wasn't this giving you errors? On 3/15/07, Bryan Cox <co...@od...> wrote:=20 Thanks, Austin! =09 I copied your script verbatim, and it works. However, it doesn't make any difference whether I include the space after the prompt or not. It works in either case. ( Well, the space is included in $sftp->before(), but that's beside the=20 point. ) =09 So now I'll start turning your script into mine incrementally until it breaks. =09 I'll let you know what I discover. =09 Bryan =09 -----Original Message----- From: Austin Schutz [mailto: te...@of...] Sent: Thursday, March 15, 2007 2:40 PM To: Bryan Cox Cc: Bradford Ritchie; exp...@li...=20 Subject: Re: [Expectperl-discuss] Expect.pm & sftp =09 On Wed, Mar 14, 2007 at 02:27:17PM -0700, Bryan Cox wrote: > Here's an update: > > I've tried sftp, ftp, and rlogin. All fail in the same way:=20 > > -> spawn id(4): Does `' > -> match: > -> pattern #1: -re `(?-xism:ame.*:)'? No. > -> pattern #2: -re `(?-xism:assword:)'? No. > -> pattern #3: -re `(?-xism:ftp>)'? No.=20 > -> pattern #4: -re `(?-xism:(\n)|(\r))'? No. > -> Waiting for new data (10 seconds)... > -> TIMEOUT > =09 This may be failing because of a race condition. You are not waiting for a space after 'sftp>'. I have a simple script I was able to use to get a listing of files from sftp, so I don't think sftp itself is doing anything odd: =09 #!/usr/bin/perl use Expect;=20 =09 # usage: test.pl <[username@]host> <password> =09 $sftp =3D Expect->spawn('sftp ' . $ARGV[0]); $sftp->exp_internal(1); $sftp->expect(10, 'ord: '); print $sftp $ARGV[1]."\r"; $sftp->expect(10,=20 'sftp> '); print $sftp "ls\r"; $sftp->expect(10, 'sftp> '); print "Files:" . $sftp->before(); =09 It's important to make sure you have received all the output=20 from the remote host before sending it anything. It may flush its buffers before reading, thereby dumping whatever you thought you sent it. =09 Austin =09 |
From: John B. (Lists) <li...@jo...> - 2007-03-20 11:18:02
|
Hi Ronald, That works perfectly. Thanks! John On Tue, 2007-03-20 at 11:22 +0100, Roland Giersig wrote: > how about > > my $promptRE = join("|", keys %args); > > $exp->expect($timeout, > [ > qr/^($promptRE) /, > sub { > $self = shift; > my $prompt = ($self->matchlist())[0]; > $self ->send($args{$prompt}, "\n"); > exp_continue > } > ], > ); > > to use a list of responses in the hash to be able to handle multiple > occurances of the same prompt is left as an exercise to the reader... > :-) |
From: Roland G. <rgi...@cp...> - 2007-03-20 10:22:43
|
how about my $promptRE = join("|", keys %args); $exp->expect($timeout, [ qr/^($promptRE) /, sub { $self = shift; my $prompt = ($self->matchlist())[0]; $self ->send($args{$prompt}, "\n"); exp_continue } ], ); to use a list of responses in the hash to be able to handle multiple occurances of the same prompt is left as an exercise to the reader... :-) On 3/20/07, John Bradshaw (Lists) <li...@jo...> wrote: > Hi all, > > Trying to drive an interactive session with some telecomms kit. It's a > very simple interface - it gives a series of fixed prompts to which the > user enters a response, nothing fancy but quite tedious. > > I have a Perl hash with the prompts as keys and the responses as the > hashed values. > > Example of a session... > REQ NEW > TYPE TIE > CUST 0 > ... > where REQ, TYPE and CUST are the kit's prompts - always on a new line > ending with a space. NEW, TIE and 0 are the corresponding responses. > > So the draft code is... > > $exp->expect($timeout, > [ > qr/^REQ /, > sub { > $self = shift; > $self ->send($args{"REQ"}, "\n"); > exp_continue > } > ], > [ > qr/^TYPE /, > sub { > $self = shift; > $self ->send($args{"TYPE"}, "\n"); > exp_continue; > } > ], > [ > qr/^CUST /, > sub { > $self = shift; > $self ->send($args{"CUST"}, "\n"); > exp_continue; > } > ], > # Hundreds more patterns here... > ... > ... > ); > > This works fine however I'd like to build the expect loop during > execution using the %args hash as it's easier to add hash pairs than > have to modify code when a new prompt appears. > > Is this supported with Expect.pm? If so, any hints on the best way to > code this? > > Thanks, > John. > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |
From: John B. (Lists) <li...@jo...> - 2007-03-19 23:42:25
|
Hi all, Trying to drive an interactive session with some telecomms kit. It's a very simple interface - it gives a series of fixed prompts to which the user enters a response, nothing fancy but quite tedious. I have a Perl hash with the prompts as keys and the responses as the hashed values. Example of a session... REQ NEW TYPE TIE CUST 0 ... where REQ, TYPE and CUST are the kit's prompts - always on a new line ending with a space. NEW, TIE and 0 are the corresponding responses. So the draft code is... $exp->expect($timeout, [ qr/^REQ /, sub { $self = shift; $self ->send($args{"REQ"}, "\n"); exp_continue } ], [ qr/^TYPE /, sub { $self = shift; $self ->send($args{"TYPE"}, "\n"); exp_continue; } ], [ qr/^CUST /, sub { $self = shift; $self ->send($args{"CUST"}, "\n"); exp_continue; } ], # Hundreds more patterns here... ... ... ); This works fine however I'd like to build the expect loop during execution using the %args hash as it's easier to add hash pairs than have to modify code when a new prompt appears. Is this supported with Expect.pm? If so, any hints on the best way to code this? Thanks, John. |
From: <al....@ac...> - 2007-03-19 22:12:30
|
Hi Ronald, I have used your recommended approach in the past on my Sun servers with great success. Unfortunately due to the proprietary nature of the OS running on my non Sun remote servers the capability of setting up SSH keys is not supported.=20 After enabling exp-internal() in my script I found couple of \r\n in the prompt and was able to fix the issue. =20 Thank you all for your help. =20 =20 Al =20 -----Original Message----- From: der...@gm... [mailto:der...@gm...] On Behalf Of Roland Giersig Sent: Saturday, March 17, 2007 2:00 PM To: Pashazadeh, Al Cc: exp...@li... Subject: Re: [Expectperl-discuss] Multi Line Prompts - Help A classical example of a problem best solved by NOT using Expect... :-) Just set up ssh keys so you can log in without giving a password. This means that you have to log in to each server once to get its fingerprint into your known_hosts file and to add your public key to the authorized_keys file. Hope this helps... Roland On 3/15/07, al....@ac... <al....@ac...> wrote: > > Hello everyone, > > I need a bit of help with figuring out a problem with my Expect Perl script > and was hoping someone on the list might be able to point me in right > direction. I use Expect Perl module in my script for executing commands > remotely on some of my servers. The script uses Open SSH (4.2p1) on Solaris > 2.8 for logging into each remote server. The remote servers run on a > proprietary UNIX OS which can send back any of the following single or multi > line prompts during the SSH attempt: > > > > The authenticity of host 'testserver (10.10.11.12)' can't be established. > > RSA key fingerprint is > 8e:be:a4:4c:55:09:e8:72:f8:2b:e9:60:0c:84:f6:39. > > Are you sure you want to continue connecting (yes/no)? > > > > or > > > > User1@testserver's password: > > > > or > > > > Blank line > > Blank line > > Data ONTAP (testserver.domainname.com) > > login: > > > > For checking the prompts I am trying something similar to the following: > > > > $Prompt =3D 'Are you sure you want to continue connecting (yes/no)? '; - This > is the last line from the first prompt above. > > > > $which =3D $exp->expect ( 20, "$user_id\@$host_ip\'s password: ",$Prompt, > "login: ","[local_host_name%#]" ); > > > > I am using $which variable to find out which prompt is matched. This > appears to be working for the first two prompts but not for the third one. > I enabled logging to a file and noticed the following when opened the log > file via vi: > > > > ^M > > ^M > > Data OnTap (testserver.domainname.com)^M > > login: > > > > I can't tell if there is any other hidden character in the above prompt. I > don't know what regular expression to use to match for the above multi line > prompt and am not sure why the $Prompt work for the first multi line prompt. > Currently the following packages are installed on my Sun box: > > > > expect-5.43.0-sol8-sparc-local > > Expect-1.20 > > IO-Tty-1.07 > > perl-5.8.7-sol8-sparc-local > > > > Any help is appreciated. > > > > > > > > > > > > > This message is for the designated recipient only and may contain > privileged, proprietary, or otherwise private information. If you have > received it in error, please notify the sender immediately and delete the > original. Any other use of the email by you is prohibited. > ------------------------------------------------------------------------ - > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3D= DEVDE V > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > This message is for the designated recipient only and may contain = privileged, proprietary, or otherwise private information. If you have = received it in error, please notify the sender immediately and delete = the original. Any other use of the email by you is prohibited. |
From: Roland G. <rgi...@cp...> - 2007-03-19 16:12:13
|
even Net::SFTP? which should be a pure-perl-implementation? On 3/19/07, Blackstone, J. David <jda...@ci...> wrote: > -----Original Message----- > From: exp...@li... > [mailto:exp...@li...] On Behalf Of > Roland Giersig > Sent: Monday, March 19, 2007 15:36 > To: Bryan Cox > Cc: exp...@li... > Subject: Re: [Expectperl-discuss] Expect.pm & sftp > > > hmm, first of all, why do you have to use sftp? how about using scp? > :o) > > I know that I personally have a pair of very unfortunate situations > where the vendor of a certain piece of equipment allows sftp but does > not allow scp. I have no idea how they even configure it to work that > way. > > It's awful because Perl's various sftp interface modules are somewhat > buggy. > > Jdb > |
From: Roland G. <rgi...@cp...> - 2007-03-19 15:36:31
|
hmm, first of all, why do you have to use sftp? how about using scp? :o) i wrote the example script below und tried it on cygwin, linux and aix. it works on both cygwin und aix, but has problems on linux, it doesn't capture the 'ls' output. so i guess there is something fishy with the pty on linux. the prompt correctly goes to Expects pty but the 'ls' output somehow manages to go directly to the terminal... :-( my $sftp = Expect->spawn("sftp $ARGV[0]"); my $sentLS; my $result; $sftp->expect(10, [ qr/sftp> \Z/ => sub { if ($sentLS) { $sftp->send("quit\r"); } else { $sftp->send("ls -1\r"); $sentLS = 1; } exp_continue; } ], [ qr/.+/ => sub { $result .= $sftp->match(); exp_continue; } ], [ timeout => sub { print "Timeout\n" } ], [ eof => sub { print "EOF\n" } ], ); $result =~ s{\r(?!\n)}{\n}g; $result =~ s{^}{>< }smg; print "$result\n"; On 3/13/07, Bryan Cox <co...@od...> wrote: > > > So, I've combed the archives and found similar problems, but no solution > (usually pty settings) that works for me. > > I can't install Net::SFTP, so I'm trying to implement an automated sftp via > Expect. > The example below uses a password login, but the problem is exactly the same > if I > use publickey authorization. > > > > # Spawn the sftp process > if ( not $expect->spawn( $_sftp_program, @cmd_parameters ) ) { > carp "ERROR: Unable to spawn $_sftp_program : $OS_ERROR\n"; > } > else { > $expect->restart_timeout_upon_receive(1); > > # Wait for prompt, send password if necessary > my @expect_result = $expect->expect( $_expect_timeout, > [ '-re', qr/password:/ => > sub { my $exp_self = shift; > print "\n\n-- sftp password prompt detected.\n" > if ( ( $self->verbose() > 1 ) > or $self->debug_ftp() ); > $exp_self->send( $self->password() . "\n" ); > print "-- sftp password sent\n\n" > if ( ( $self->verbose() > 1 ) > or $self->debug_ftp() ); > exp_continue() ; > } > ], > [ '-re', qr/$_sftp_prompt/ ], > # [ '-re', qr/(\n)|(\r)/ ] > ); > > The process spawns ok, and the password prompt is detected. The send() > works, and > the log shows that the password is accepted. After that, expect sees > nothing except a line return. > If I expect() on that (commented out above), I can then issue a send( "ls\n" > ). Again, expect() sees nothing, > but I can see the results and the prompt delivered to my terminal, usually > AFTER the timeout (depending on pty settings). > > In the log, the last line before timeout is generally around > > debug1: Authentication succeeded (password).^M > debug2: fd 4 setting O_NONBLOCK^M > debug3: fd 5 is O_NONBLOCK^M > debug2: fd 6 setting O_NONBLOCK^M > debug1: channel 0: new [client-session]^M > debug3: ssh_session2_open: channel_new: 0^M > debug2: channel 0: send open^M > debug1: Entering interactive session.^M > > On screen, I see > > -> -- sftp password sent > -> Continuing expect, restarting timeout... > -> spawn id(4): Does ` ' > -> match: > -> pattern #1: -re `(?-xism:password:)'? No. > -> pattern #2: -re `(?-xism:sftp>)'? No. > -> pattern #3: -re `(?-xism:(\n)|(\r))'? No. > -> Waiting for new data (10 seconds)... > -> spawn id(4): new data. > -> spawn id(4): read 2 byte(s). > -> spawn id(4): Does ` \r\n' > -> match: > -> pattern #1: -re `(?-xism:password:)'? No. > -> pattern #2: -re `(?-xism:sftp>)'? No. > -> pattern #3: -re `(?-xism:(\n)|(\r))'? YES!! > -> Before match string: ` ' > -> Match string: `\r' > -> After match string: `\n' > -> Matchlist: (`', `\r') > -> Returning from expect successfully. > -> spawn id(4): accumulator: `\n' > Retrieving a list of remote files .. > -> Sending 'ls\n' to spawn id(4) > -> at /home/coxb/lib/Expect.pm line 1277 > -> Expect::print('Expect=GLOB(0x30a2ca94)', 'ls\x{a}') > called at /home/coxb/lib/ODS/FtpSftp.pm line 396 > -> > ODS::FtpSftp::_list_files_sftp('ODS::FtpSftp=HASH(0x30a2b588)') > called at /home/coxb/lib/ODS/FtpSftp.pm line 96 > -> > ODS::FtpSftp::list_files('ODS::FtpSftp=HASH(0x30a2b588)') > called at /file_xfer line 253 > -> expect(Expect=GLOB(0x30a2ca94) 10 ARRAY(0x30a2f2ec)) called... > -> expect(): handling param 'ARRAY(0x30a2f2ec)'... > -> Starting EXPECT pattern matching... > -> at /home/coxb/lib/Expect.pm line 564 > -> Expect::expect('Expect=GLOB(0x30a2ca94)', 10, > 'ARRAY(0x30a2f2ec)') called at /home/coxb/lib/ODS/FtpSftp.pm line 397 > -> > ODS::FtpSftp::_list_files_sftp('ODS::FtpSftp=HASH(0x30a2b588)') > called at /home/coxb/lib/ODS/FtpSftp.pm line 96 > -> > ODS::FtpSftp::list_files('ODS::FtpSftp=HASH(0x30a2b588)') > called at /file_xfer line 253 > -> spawn id(4): beginning expect. > -> Timeout: 10 seconds. > -> Current time: Tue Mar 13 12:47:43 2007 > -> spawn id(4): list of patterns: > -> #1: -re `(?-xism:sftp>)' > -> spawn id(4): Does `\n' > -> match: > -> pattern #1: -re `(?-xism:sftp>)'? No. > -> Waiting for new data (10 seconds)... > -> spawn id(4): new data. > -> spawn id(4): read 4 byte(s). > -> ls > -> spawn id(4): Does `\nls\r\n' > -> match: > -> pattern #1: -re `(?-xism:sftp>)'? No. > -> Waiting for new data (10 seconds)... > -> sftp> THEFILEIMLOOKINGFOR.DAT > -> sftp> TIMEOUT > > I've tried every stty setting for both control and slave, including -file. > Nothing works. > > I'm connecting from AIX 5.3 back to myself, so the machine is known. > > I'd really appreciate some help on this. > > Thanks, > > -- Bryan > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > |
From: Johnson, W. <wr...@sa...> - 2007-03-19 14:06:44
|
It took me a long time, but I came to the same conclusion a couple years = ago. If your installation permits, you can use -o 'StrictHostKeyChecking no' = on the ssh command line and you won't have to worry about keys at all. = They will be automatically set up for you. % ssh -o 'StrictHostKeyChecking no' <yourhost> Note the ticks on the option. Good luck. Wilbur R. Johnson Software Systems Systems Engineering and Analysis Sandia National Laboratories PMTS - Software Research and Development=20 -----Original Message----- From: exp...@li... on behalf of = Roland Giersig Sent: Sat 3/17/2007 1:00 PM To: al....@ac... Cc: exp...@li... Subject: Re: [Expectperl-discuss] Multi Line Prompts - Help =20 A classical example of a problem best solved by NOT using Expect... :-) Just set up ssh keys so you can log in without giving a password. This means that you have to log in to each server once to get its fingerprint into your known_hosts file and to add your public key to the authorized_keys file. Hope this helps... Roland On 3/15/07, al....@ac... <al....@ac...> = wrote: > > Hello everyone, > > I need a bit of help with figuring out a problem with my Expect Perl = script > and was hoping someone on the list might be able to point me in right > direction. I use Expect Perl module in my script for executing = commands > remotely on some of my servers. The script uses Open SSH (4.2p1) on = Solaris > 2.8 for logging into each remote server. The remote servers run on a > proprietary UNIX OS which can send back any of the following single or = multi > line prompts during the SSH attempt: > > > > The authenticity of host 'testserver (10.10.11.12)' can't be = established. > > RSA key fingerprint is > 8e:be:a4:4c:55:09:e8:72:f8:2b:e9:60:0c:84:f6:39. > > Are you sure you want to continue connecting (yes/no)? > > > > or > > > > User1@testserver's password: > > > > or > > > > Blank line > > Blank line > > Data ONTAP (testserver.domainname.com) > > login: > > > > For checking the prompts I am trying something similar to the = following: > > > > $Prompt =3D 'Are you sure you want to continue connecting (yes/no)? '; = - This > is the last line from the first prompt above. > > > > $which =3D $exp->expect ( 20, "$user_id\@$host_ip\'s password: = ",$Prompt, > "login: ","[local_host_name%#]" ); > > > > I am using $which variable to find out which prompt is matched. This > appears to be working for the first two prompts but not for the third = one. > I enabled logging to a file and noticed the following when opened the = log > file via vi: > > > > ^M > > ^M > > Data OnTap (testserver.domainname.com)^M > > login: > > > > I can't tell if there is any other hidden character in the above = prompt. I > don't know what regular expression to use to match for the above multi = line > prompt and am not sure why the $Prompt work for the first multi line = prompt. > Currently the following packages are installed on my Sun box: > > > > expect-5.43.0-sol8-sparc-local > > Expect-1.20 > > IO-Tty-1.07 > > perl-5.8.7-sol8-sparc-local > > > > Any help is appreciated. > > > > > > > > > > > > > This message is for the designated recipient only and may contain > privileged, proprietary, or otherwise private information. If you have > received it in error, please notify the sender immediately and delete = the > original. Any other use of the email by you is prohibited. > = -------------------------------------------------------------------------= > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to = share your > opinions on IT & business topics through brief surveys-and earn cash > = http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3D= DEVDEV > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > -------------------------------------------------------------------------= Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share = your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3D= DEVDEV _______________________________________________ Expectperl-discuss mailing list Exp...@li... https://lists.sourceforge.net/lists/listinfo/expectperl-discuss |
From: Roland G. <rgi...@cp...> - 2007-03-17 19:00:21
|
A classical example of a problem best solved by NOT using Expect... :-) Just set up ssh keys so you can log in without giving a password. This means that you have to log in to each server once to get its fingerprint into your known_hosts file and to add your public key to the authorized_keys file. Hope this helps... Roland On 3/15/07, al....@ac... <al....@ac...> wrote: > > Hello everyone, > > I need a bit of help with figuring out a problem with my Expect Perl script > and was hoping someone on the list might be able to point me in right > direction. I use Expect Perl module in my script for executing commands > remotely on some of my servers. The script uses Open SSH (4.2p1) on Solaris > 2.8 for logging into each remote server. The remote servers run on a > proprietary UNIX OS which can send back any of the following single or multi > line prompts during the SSH attempt: > > > > The authenticity of host 'testserver (10.10.11.12)' can't be established. > > RSA key fingerprint is > 8e:be:a4:4c:55:09:e8:72:f8:2b:e9:60:0c:84:f6:39. > > Are you sure you want to continue connecting (yes/no)? > > > > or > > > > User1@testserver's password: > > > > or > > > > Blank line > > Blank line > > Data ONTAP (testserver.domainname.com) > > login: > > > > For checking the prompts I am trying something similar to the following: > > > > $Prompt = 'Are you sure you want to continue connecting (yes/no)? '; - This > is the last line from the first prompt above. > > > > $which = $exp->expect ( 20, "$user_id\@$host_ip\'s password: ",$Prompt, > "login: ","[local_host_name%#]" ); > > > > I am using $which variable to find out which prompt is matched. This > appears to be working for the first two prompts but not for the third one. > I enabled logging to a file and noticed the following when opened the log > file via vi: > > > > ^M > > ^M > > Data OnTap (testserver.domainname.com)^M > > login: > > > > I can't tell if there is any other hidden character in the above prompt. I > don't know what regular expression to use to match for the above multi line > prompt and am not sure why the $Prompt work for the first multi line prompt. > Currently the following packages are installed on my Sun box: > > > > expect-5.43.0-sol8-sparc-local > > Expect-1.20 > > IO-Tty-1.07 > > perl-5.8.7-sol8-sparc-local > > > > Any help is appreciated. > > > > > > > > > > > > > This message is for the designated recipient only and may contain > privileged, proprietary, or otherwise private information. If you have > received it in error, please notify the sender immediately and delete the > original. Any other use of the email by you is prohibited. > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > |
From: Aiman H. <ha...@gm...> - 2007-03-16 11:50:13
|
Hi Austin, Thanks very much. You save my day.. This is what I look for, and you're also right in space in sftp prompt. It works before just because it is time out.. w/o I realised it. Anyhow.. thanks again!! Regards. On 3/16/07, Austin Schutz <te...@of...> wrote: > > On Fri, Mar 16, 2007 at 03:18:31AM +0800, Aiman Hakimie wrote: > > Hi, > > > > I'm new to this Expect. Just found out and decided to use in my current > > project assignment. Really appreciate any help. I've trying to look > > somewhere else (unsuccessfully) before decided to post it here. > > > > I want to use expect to do sftp. After login, I'll get the list of > available > > files in the directory, and from the list, I'll need to do some matching > > with localhost list to get the file that is not in the local host. > > > > I trying to do something like this: > > ....... > > ........ > > my $ret = $exp->expect(30,"sftp>") || die "Timeout waiting for sftp.\n"; > > $exp->send("cd /tmp\n"); > > > > $exp->expect(10,"sftp>"); > > my @file=$exp->send("ls A*\n"); > > > > foreach $file (@file) { > > #do comparison > > # if not match, > > $exp->send("get $file\n"); > > } > > ..... > > .... > > > > > > Line "my @file=$exp->send("ls A*\n");" does;t give me the file list that > I > > want. I can do like this using Net::FTP, but not using Expect. > > > > Is there any way to achieve this? > > sftp (on my machine) uses the prompt 'sftp> '. That space is > important. > Typically you want to send \r instead of \n, that may or may not > matter here. > Use $exp->exp_internal(1) so you can watch what is sent/received. > $exp->before() contains output before the last expect() match. in > this case it will have the output of ls. > > Austin > |
From: Bradford R. <bt...@po...> - 2007-03-16 04:06:41
|
Bryan, Looking at your code more closely, have you tried replacing qr/$_sftp_prompt/ with a literal string like qr/myprompt%/ or 'myprompt' ? Might be worth a try since the other two expect lines seem to be succeeding for you. Also, not that it matters, but I noticed that in sub that handles the password, you define $exp_self to hold the expect object instance, but then call $self->verbose(). Wasn't this giving you errors? On 3/15/07, Bryan Cox <co...@od...> wrote: > > Thanks, Austin! > > I copied your script verbatim, and it works. > However, it doesn't make any difference whether I include the space > after the prompt or not. It works in either case. > ( Well, the space is included in $sftp->before(), but that's beside the > point. ) > > So now I'll start turning your script into mine incrementally until it > breaks. > > I'll let you know what I discover. > > Bryan > > -----Original Message----- > From: Austin Schutz [mailto:te...@of...] > Sent: Thursday, March 15, 2007 2:40 PM > To: Bryan Cox > Cc: Bradford Ritchie; exp...@li... > Subject: Re: [Expectperl-discuss] Expect.pm & sftp > > On Wed, Mar 14, 2007 at 02:27:17PM -0700, Bryan Cox wrote: > > Here's an update: > > > > I've tried sftp, ftp, and rlogin. All fail in the same way: > > > > -> spawn id(4): Does `' > > -> match: > > -> pattern #1: -re `(?-xism:ame.*:)'? No. > > -> pattern #2: -re `(?-xism:assword:)'? No. > > -> pattern #3: -re `(?-xism:ftp>)'? No. > > -> pattern #4: -re `(?-xism:(\n)|(\r))'? No. > > -> Waiting for new data (10 seconds)... > > -> TIMEOUT > > > > This may be failing because of a race condition. You are not > waiting for a space after 'sftp>'. > I have a simple script I was able to use to get a listing of > files from sftp, so I don't think sftp itself is doing anything odd: > > #!/usr/bin/perl > use Expect; > > # usage: test.pl <[username@]host> <password> > > $sftp = Expect->spawn('sftp ' . $ARGV[0]); $sftp->exp_internal(1); > $sftp->expect(10, 'ord: '); print $sftp $ARGV[1]."\r"; $sftp->expect(10, > 'sftp> '); print $sftp "ls\r"; $sftp->expect(10, 'sftp> '); print > "Files:" . $sftp->before(); > > It's important to make sure you have received all the output > from the remote host before sending it anything. It may flush its > buffers before reading, thereby dumping whatever you thought you sent > it. > > Austin > |
From: Bryan C. <co...@od...> - 2007-03-15 22:40:35
|
Thanks, Austin! I copied your script verbatim, and it works. However, it doesn't make any difference whether I include the space after the prompt or not. It works in either case. ( Well, the space is included in $sftp->before(), but that's beside the point. ) So now I'll start turning your script into mine incrementally until it breaks. I'll let you know what I discover. Bryan=20 -----Original Message----- From: Austin Schutz [mailto:te...@of...]=20 Sent: Thursday, March 15, 2007 2:40 PM To: Bryan Cox Cc: Bradford Ritchie; exp...@li... Subject: Re: [Expectperl-discuss] Expect.pm & sftp On Wed, Mar 14, 2007 at 02:27:17PM -0700, Bryan Cox wrote: > Here's an update: > =20 > I've tried sftp, ftp, and rlogin. All fail in the same way: > =20 > -> spawn id(4): Does `' > -> match: > -> pattern #1: -re `(?-xism:ame.*:)'? No. > -> pattern #2: -re `(?-xism:assword:)'? No. > -> pattern #3: -re `(?-xism:ftp>)'? No. > -> pattern #4: -re `(?-xism:(\n)|(\r))'? No. > -> Waiting for new data (10 seconds)... > -> TIMEOUT >=20 This may be failing because of a race condition. You are not waiting for a space after 'sftp>'. I have a simple script I was able to use to get a listing of files from sftp, so I don't think sftp itself is doing anything odd: #!/usr/bin/perl use Expect; # usage: test.pl <[username@]host> <password> $sftp =3D Expect->spawn('sftp ' . $ARGV[0]); $sftp->exp_internal(1); $sftp->expect(10, 'ord: '); print $sftp $ARGV[1]."\r"; $sftp->expect(10, 'sftp> '); print $sftp "ls\r"; $sftp->expect(10, 'sftp> '); print "Files:" . $sftp->before(); It's important to make sure you have received all the output from the remote host before sending it anything. It may flush its buffers before reading, thereby dumping whatever you thought you sent it. Austin |
From: Austin S. <te...@of...> - 2007-03-15 21:55:35
|
On Wed, Mar 14, 2007 at 02:27:17PM -0700, Bryan Cox wrote: > Here's an update: > > I've tried sftp, ftp, and rlogin. All fail in the same way: > > -> spawn id(4): Does `' > -> match: > -> pattern #1: -re `(?-xism:ame.*:)'? No. > -> pattern #2: -re `(?-xism:assword:)'? No. > -> pattern #3: -re `(?-xism:ftp>)'? No. > -> pattern #4: -re `(?-xism:(\n)|(\r))'? No. > -> Waiting for new data (10 seconds)... > -> TIMEOUT > This may be failing because of a race condition. You are not waiting for a space after 'sftp>'. I have a simple script I was able to use to get a listing of files from sftp, so I don't think sftp itself is doing anything odd: #!/usr/bin/perl use Expect; # usage: test.pl <[username@]host> <password> $sftp = Expect->spawn('sftp ' . $ARGV[0]); $sftp->exp_internal(1); $sftp->expect(10, 'ord: '); print $sftp $ARGV[1]."\r"; $sftp->expect(10, 'sftp> '); print $sftp "ls\r"; $sftp->expect(10, 'sftp> '); print "Files:" . $sftp->before(); It's important to make sure you have received all the output from the remote host before sending it anything. It may flush its buffers before reading, thereby dumping whatever you thought you sent it. Austin |
From: Austin S. <te...@of...> - 2007-03-15 21:42:24
|
On Fri, Mar 16, 2007 at 03:18:31AM +0800, Aiman Hakimie wrote: > Hi, > > I'm new to this Expect. Just found out and decided to use in my current > project assignment. Really appreciate any help. I've trying to look > somewhere else (unsuccessfully) before decided to post it here. > > I want to use expect to do sftp. After login, I'll get the list of available > files in the directory, and from the list, I'll need to do some matching > with localhost list to get the file that is not in the local host. > > I trying to do something like this: > ....... > ........ > my $ret = $exp->expect(30,"sftp>") || die "Timeout waiting for sftp.\n"; > $exp->send("cd /tmp\n"); > > $exp->expect(10,"sftp>"); > my @file=$exp->send("ls A*\n"); > > foreach $file (@file) { > #do comparison > # if not match, > $exp->send("get $file\n"); > } > ..... > .... > > > Line "my @file=$exp->send("ls A*\n");" does;t give me the file list that I > want. I can do like this using Net::FTP, but not using Expect. > > Is there any way to achieve this? sftp (on my machine) uses the prompt 'sftp> '. That space is important. Typically you want to send \r instead of \n, that may or may not matter here. Use $exp->exp_internal(1) so you can watch what is sent/received. $exp->before() contains output before the last expect() match. in this case it will have the output of ls. Austin |