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. |