Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
P is for Practical
 
PerlMonks  

perl expect prompt

by Anonymous Monk
on Jun 26, 2001 at 20:06 UTC ( [id://91734]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have the following script which works fine on all of my servers except for one.The problem is that for this particular server, it is not waiting for the previous command to finish before it sends the next command. I have assured myself that the prompt variable is unique, any help would be appreciated.
sub run_command { my ($in_prompt,$in_command)=@_; print $rlogin "$in_command\r"; $rlogin->expect(300,'-re',$in_prompt); }#end run_command sub rlogin { my ($in_hostname,$in_password,$in_prompt,$in_type)=@_; $rlogin=Expect->spawn($in_type." ".$in_hostname); $rlogin->expect(300,"ssword:") || die "Never got password prom +pt on $host, ".$rlogin->exp_error()."\n"; print $rlogin "$in_password\r"; $match=$rlogin->expect(300,"closed by foreign host","-re",$in_ +prompt); #Used for debugging I think #die "Dumped by server\n" if $match == 1; #die "Never got shell prompt on $host, ".$rlogin->exp_error(). +"\n" unless $match; }#end rlogin rlogin($hostname,$password,$prompt,"ssh"); run_command($prompt,"export ORACLE_SID=$oracle_sid"); run_command($prompt,"cd dev"); run_command($prompt,"chmod +x *"); run_command($prompt,"exp $schema/$schema file=$file log=$log rows=no") +; run_command($prompt,"imp $schema/$schema file=$file indexfile=$indexfi +le full=y"); run_command($prompt,"./initial.pl ".$schema."_tabind LOC_".$touser." +$touser $schema ");

Edit 2001-26-06 Masem - Added code tags

Replies are listed 'Best First'.
Re: perl expect prompt
by TheoPetersen (Priest) on Jun 26, 2001 at 20:37 UTC
    Given that it appears you are logging in via SSH anyway, can you use Net::SSH::Perl instead of using Expect directly? It handles command execution on its own; maybe it is clever enough to work around what ever is causing your prompt problem.

    In any event, it would clear out the login and command management code from your script.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://91734]
Approved by root
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.