I am trying to automate an installation of a backup client, the challenge I am facing is the below question will be asked during installation 2 times. "Enter pack name" The first time I need to pass a value "NB_CLT_7.6.0.2" and next time I need to pass a value "q". Every time when I run the script, it is passing a value "NB_CLT_7.6.0.2" both the times and the installation never ends. The below is my code and how to make sure I pass 2 values for the same questions.
use strict; use File::Copy; use Expect; my $timeout = '320'; my $current = qx{pwd}; my $NB = 'NetBackup_7.6.0.1_CLIENTS2.tar.gz'; my $patch = 'NB_CLT_7.6.0.2_Patch.tar'; my $patchtar = `/bin/tar -xf $patch`; chdir("/app"); my $exp = Expect->spawn("./NB_update.install -s"); $exp->expect($timeout, [ qr/Enter pack name \(or q\) \[q\]:\s+/ => sub { $exp->send("NB_CLT_7.6.0.2\r"); exp_continue; } ], [ qr/Do you want to kill all NetBackup daemons\? \[y,n\] \(y\) +\s+/ => sub { $exp->send("\r"); exp_continue; } ], [ qr/Do you want to continue the install\? \[y,n\] \(n\)\s+/ = +> sub { $exp->send("y\r"); exp_continue; } ], [ qr/Enter pack name \(or q\) \[q\]: \(q\)\\s+/ => sub { $exp->send("\r"); exp_continue; } ], [ qr/Do you want to restart all NetBackup daemons\? \[y,n\] \( +y\)\s+/ => sub { $exp->send("\r"); exp_continue; } ], ); $exp->soft_close(); chdir("../");

In reply to Need help on expect by toaravind

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.