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