Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Expect prints command to console

by daphnaw (Acolyte)
on Jun 20, 2010 at 15:47 UTC ( #845637=perlquestion: print w/ replies, xml ) Need Help??
daphnaw has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have been using the Expect module to run a script which installs Oracle as user root. The problem is that the executing command itself which contains passwords is printed to the console, although raw_pty & log_stdout are set to 0:
my $tmp_dir = Cwd::abs_path(dirname($0)); eval "use Expect;"; if ($@) { crash "Could not find Expect"; } my $exp = Expect->new; $exp->raw_pty(0); $exp->log_stdout(0); $exp->spawn("su - root"); $exp->expect($timeout, [ '-re', 'Password:\s*$' => sub { $exp->send("$root_password\n"); }], [ timeout => sub { die "Timeout" }], ); $exp->expect($timeout, [ '-re', '\][#%]\s*$' => sub {} ], [ timeout => sub { die "Timeout, no prompt" } ], ); my $script = basename $0; $cmd = "cd $tmp_dir; $^X $script $cmd"; PERLLIB ''; $^X $script $cmd"; <b>$cmd = "($cmd)";</b> my $result = $exp->send("$cmd\n"); my $success; my $end_string_seen; my $time_cnt = 1000; $exp->expect($timeout, [ '-re', '\][#%]\s*$'=> sub {} ], ['-re', $END_STRING => sub { $end_string_seen = 1;} ], [ '-re', $SUCCESS_STRING => sub { $success = 1; } ], [ timeout => sub { print $exp->before; $exp->clear_accum; $time_cnt--; if ($time_cnt > 0) { exp_continue(); } else { die "Timeout, no prompt"; } } ], ); if ($success) { $exp->soft_close(); } else { crash("Installation failed"); } exit 0;
$cmd is printed to the console: (cd /export/home/ana37/local/scripts/embedded_oracle; /export/home/ana37/local/scripts/embedded_oracle/perl/bin/perl-static oracle.pl --host localhost --remove --install --oraclepw Fx9qYfmz --oracleuser oracle --oraclehome /export/home/oracle --rootpw admin --datafiles /export/home/oracle/oradata/anadb --redo /export/home/oracle/redo --recovery /export/home/oracle/arch --smtp_server outbound.cisco.com --email_recipient dwasserm@cisco.com)

Comment on Expect prints command to console
Download Code
Re: Expect prints command to console
by Illuminatus (Curate) on Jun 21, 2010 at 00:26 UTC
    Why are you setting raw_pty to 0? You want raw_pty turned on. In 'stty' land, raw mode means no echo.
      Setting $exp->raw_pty(1) didnt make a difference. The command is still pronted the the console. Any ideas? Thanks
Re: Expect prints command to console
by Krambambuli (Deacon) on Jun 21, 2010 at 15:50 UTC
    Might help to make your code snippet runnable - what sort of Perl do you use ?

    I wanted to give it a try, but my Perl doesn't know what 'crash' is, so I get only compile errors.

    Is that
    $cmd = "cd $tmp_dir; $^X $script $cmd";
    line you have correct ? Isn't $cmd undefined when the string is evaluated ?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://845637]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2014-12-21 09:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (104 votes), past polls