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

Hi PerlMonks,

I have automated an interactive remote ssh session which executes a command , looks for a warning message and then provides the option "y" in response to the warning message.

The issue that i am facing is that the option "y" is provided a second time on the command line generating an error.

How do i get to print this input option only once in response to the warning message and not a second time.

The codelet is mentioned below ($confref->{'ssh_session'} is the spawn id of the ssh session):

$confref->{'ssh_session'}->clear_accum(); $confref->{'ssh_session'}->send("$cmd\n"); $confref->{'ssh_session'}->expect( undef,[ '{y|n}:', sub { my $fh = shift; print $fh "y\n"; $pass_flag = 1; exp_continue; } ] ,-re, qr'./*> $' ); $confref->{'ssh_session'}->clear_accum(); $info = $confref->{'ssh_session'}->before();

The output in $info is mentioned below :


f3050-233-10::> volume move -vserver f3050_233_10_vserver_cifs_1 -volume f3050_233_10_vserver_cifs_1_dynamic_vol1 -destination-aggregate aggr0 -foreground true

WARNING: You are about to move a volume to a root aggregate. This may cause severe performance or stability problems and therefore is not recommended.
Do you want to proceed? {y|n}: y
Job 498 Job succeeded: Successful 105.

f3050-233-10::> y

ERROR: "y" is not a recognized command

f3050-233-10::> Thanks in Advance!

Replies are listed 'Best First'.
Re: Perl Send-Expect Input discrepancy
by jethro (Monsignor) on Jul 08, 2009 at 12:12 UTC

    Are you using Expect? You don't say which modules you are using.

    If (as it seems) you are using Expect or the module you are using is using Expect: The expect.pm documentation for version 1.15 (and also 1.21) which is a bit sparse on some details uses $fh->send("y\n"); to send responses in the examples provided. Don't know if that makes a difference though

    Also there is a debug method you can call on the Expect object. Called with a parameter of 1, 2 or 3 you should get more information about what is happening.

      yes i am using the Expect module. Il try using the debug option.

      Thank you.

Re: Perl Send-Expect Input discrepancy
by apl (Monsignor) on Jul 08, 2009 at 12:06 UTC
    I can't answer your question, but I'm compelled to ask: What happens if you change

    print $fh "y\n";

    to

    print $fh "y";
    ?

      In that case i get the following output, and the tool hangs :

      WARNING: Are you sure you want to destroy volume f3050_233_10_vserver_cifs_2_dynamic_vol1 in vserver f3050_233_10_vserver_cifs_2 ? {y|n}: yy