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)

In reply to Expect prints command to console by daphnaw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.