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

hi all, I need help on passing yes to output of command cfgsave on brocade switch,when cfsave is executed from script it ask to also pass yes to save the config as shown below

DS_6505B:admin> cfgsave You are about to save the Defined zoning configuration. This action will only save the changes on Defined configuration. If the update includes changes to one or more traffic isolation zones, you must issue the 'cfgenable' command for the changes to take effect. Do you want to save the Defined zoning configuration only? (yes, y, n +o, n): [no]
my code is below
$logger->info("saving the zone"); ($out,$err) = $ssh->capture2("cfgsave"); $ssh->error and die "remote find command failed:$!" . $ssh->error; $logger->info("config saved");

the failure that i see is because the command expects to save by passing yes.how do i send it from the script

any help would be helpful

Replies are listed 'Best First'.
Re: issue with passing yes to the output of a command
by Myrddin Wyllt (Hermit) on Jul 26, 2015 at 17:02 UTC

    You can pass the 'yes' using NET::OpenSSH's 'stdin_data' option:

    ($out,$err) = $ssh->capture2({stdin_data => 'yes'}, "cfgsave");

    If cfgsave needs more input after the 'yes', pass it as an array ref:

    my $answers = ['yes', 'no', 'wait', 'sorry']; ($out,$err) = $ssh->capture2({stdin_data => $answers}, "cfgsave");

      Sometimes a "\n" is also needed.
Re: issue with passing yes to the output of a command
by toolic (Bishop) on Jul 26, 2015 at 13:53 UTC
Re: issue with passing yes to the output of a command
by pme (Monsignor) on Jul 26, 2015 at 14:16 UTC
    Using yes may help:
    ($out,$err) = $ssh->capture2("yes|cfgsave");

      tried above step

      ($out,$err) = $ssh->capture2("yes|cfgsave");

      getting error

      2015/07/27 02:38:56 saving the zone remote find command failed:child exited with code 248 at ./switchconfi +g.pl line 113, <$fh> line 4.
        It seems that 'cfgsave' passed the yes/no question, and looks like another issue. How does 'cfgsave' behave if you run manually?