Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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

Replies are listed 'Best First'.
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 Anonymous Monk on Apr 08, 2016 at 14:15 UTC

    Set log_stdout AFTER the spawn worked for me (it did not work if it was set before the spawn):

    $exp->spawn("su - root"); $exp->log_stdout(0); ## <<AFTER the spawn
    Apologies for answering an oldie, but it helped me.
Re: Expect prints command to console
by Krambambuli (Curate) 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://845637]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2017-12-16 21:54 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (459 votes). Check out past polls.