in reply to Re^5: issue with code to save config on brocade swicth
in thread issue with code to save config on brocade switch

adding the exact script below

#!/usr/bin/perl use strict; use warnings; use List::Util qw( first ); use Net::OpenSSH; use Log::Log4perl qw(:easy); Log::Log4perl->easy_init($INFO); use Expect; use 5.010; my $logger = get_logger(); my $username = 'admin'; my $password = 'password'; my $ip = '10.227.0.216'; $logger->info("performing ssh to the swicth"); my $ssh = Net::OpenSSH->new($ip,user=>"$username",password=>"$password +",master_opts=>[-o =>"StrictHostKeyChecking=no"]); $logger->info("listing zone on the switch $ip using zoneshow"); my($out,$err) = $ssh->capture2("zoneshow"); print "$out\n"; $logger->info("zoneshow successful"); $logger->info("listing zone on the switch $ip using nsshow"); ($out,$err) = $ssh->capture2("nsshow"); print "$out\n"; $logger->info("nsshow successful"); sleep 3; $logger->info("create zone on the switch $ip using zonecreate"); ($out,$err) = $ssh->capture2("zonecreate \"test5\", \" 20:01:00:11:0d: +34:57:00\" "); $ssh->error and die "remote find command failed: $!" . $ssh->error; print "$out\n"; $logger->info("zonecreate successful"); ##now add the zone to the config and save it ($out,$err) = $ssh->capture2("cfgadd \"FC_DVT\", \"test5\""); ($out,$err) = $ssh->capture2({stdin_data => 'yes'},"cfgsave"); ($out,$err) = $ssh->capture2({stdin_data => 'yes'},"cfgenable \"FC_DVT +\"");

the output is below,it does not throw any error thats the problem,but it doest not perform the required stpes as well

the output when script is run is below

[root@localhost jana]# vi switchconfig.pl [root@localhost jana]# ./switchconfig.pl 2015/07/29 04:53:48 performing ssh to the swicth 2015/07/29 04:53:49 listing zone on the switch 10.227.0.216 using zone +show Defined configuration: cfg: FC_DVT MEZZI; MEZZI1; test1 zone: MEZZI mezzi1; mezzi2; sanblaze zone: MEZZI1 mezzi3; mezzi4; sanblaze zone: test1 20:00:00:11:0d:34:56:00 zone: vikash_enfield 10:00:00:00:c9:a1:95:aa; 10:00:00:00:c9:a1:95:ab; 20:00:00:11:0d:34:56:00 alias: mezzi1 10:00:00:00:c9:cd:cc:6c alias: mezzi2 10:00:00:00:c9:cd:cc:6d alias: mezzi3 10:00:00:90:fa:2e:dd:9f alias: mezzi4 10:00:00:90:fa:2e:dd:a0 alias: sanblaze 20:01:00:11:0d:34:57:00 Effective configuration: cfg: FC_DVT zone: MEZZI 10:00:00:00:c9:cd:cc:6c 10:00:00:00:c9:cd:cc:6d 20:01:00:11:0d:34:57:00 zone: MEZZI1 10:00:00:90:fa:2e:dd:9f 10:00:00:90:fa:2e:dd:a0 20:01:00:11:0d:34:57:00 zone: test1 20:00:00:11:0d:34:56:00 2015/07/29 04:53:50 zoneshow successful 2015/07/29 04:53:50 listing zone on the switch 10.227.0.216 using nssh +ow { Type Pid COS PortName NodeName +TTL(sec) N 010700; 3;50:0a:09:84:88:ed:66:d4;50:0a:09:80:88:ed:66:d4; +na FC4s: FCP [NETAPP LUN 7360] Fabric Port Name: 20:07:00:05:33:d4:06:4d Permanent Port Name: 50:0a:09:84:88:ed:66:d4 Port Index: 7 Share Area: No Device Shared in Other AD: No Redirect: No Partial: No LSAN: No N 010a00; 3;10:00:00:90:fa:2e:dd:9f;20:00:00:90:fa:2e:dd:9f; +na FC4s: IPFC FCP PortSymb: [34] "Emulex PPN-10:00:00:90:fa:2e:dd:9f" NodeSymb: [37] "Emulex 7101684 FV10.6.168.0 DV3.0.02 " Fabric Port Name: 20:0a:00:05:33:d4:06:4d Permanent Port Name: 10:00:00:90:fa:2e:dd:9f Port Index: 10 Share Area: No Device Shared in Other AD: No Redirect: No Partial: No LSAN: No N 010b00; 2,3;20:00:00:11:0d:34:56:00;20:00:00:11:0d:34:56:00; +na FC4s: FCP PortSymb: [22] "SANBlaze FC Port Targ0" Fabric Port Name: 20:0b:00:05:33:d4:06:4d Permanent Port Name: 20:00:00:11:0d:34:56:00 Port Index: 11 Share Area: No Device Shared in Other AD: No Redirect: No Partial: No LSAN: No N 010e00; 2,3;20:01:00:11:0d:34:57:00;20:01:00:11:0d:34:57:00; +na FC4s: FCP PortSymb: [22] "SANBlaze FC Port Targ0" Fabric Port Name: 20:0e:00:05:33:d4:06:4d Permanent Port Name: 20:01:00:11:0d:34:57:00 Port Index: 14 Share Area: No Device Shared in Other AD: No Redirect: No Partial: No LSAN: No The Local Name Server has 4 entries } 2015/07/29 04:53:51 nsshow successful 2015/07/29 04:53:54 create zone on the switch 10.227.0.216 using zonec +reate 2015/07/29 04:53:55 zonecreate successful

when i do the cfgsave and cfgenable i also need to press 'y' or 'yes' for them to save on the switch,the problem is here i think

Replies are listed 'Best First'.
Re^7: issue with code to save config on brocade swicth
by Corion (Patriarch) on Jul 28, 2015 at 18:14 UTC

    When sending your stdin_data, you never send the carriage return.

    Also, you only ever print/check $out for content and not $err.

    I would look through the options that Net::OpenSSH offers for debugging and enable them so you can see the actual data that gets sent/received and determine from that where your script differs from the manual interaction.

      this is the error seen

      remote find command failed: child exited with code 248 at ./switchconfig.pl line 45.

      its seen when i send stdin

      code change to check each command executed

      #!/usr/bin/perl use strict; use warnings; use List::Util qw( first ); use Net::OpenSSH; use Log::Log4perl qw(:easy); Log::Log4perl->easy_init($INFO); use Expect; use 5.010; my $logger = get_logger(); my $username = 'admin'; my $password = 'password'; my $ip = '10.227.0.216'; $logger->info("performing ssh to the swicth"); my $ssh = Net::OpenSSH->new($ip,user=>"$username",password=>"$password +",master_opts=>[-o =>"StrictHostKeyChecking=no"]); $logger->info("listing zone on the switch $ip using zoneshow"); my($out,$err) = $ssh->capture2("zoneshow"); print "$out\n"; $logger->info("zoneshow successful"); $logger->info("listing zone on the switch $ip using nsshow"); ($out,$err) = $ssh->capture2("nsshow"); print "$out\n"; $logger->info("nsshow successful"); sleep 3; $logger->info("create zone on the switch $ip using zonecreate"); ($out,$err) = $ssh->capture2("zonecreate \"test5\", \" 20:01:00:11:0d: +34:57:00\" "); $ssh->error and die "remote find command failed: $!" . $ssh->error; print "$out\n"; $logger->info("zonecreate successful"); ##now add the zone to the config and save it ($out,$err) = $ssh->capture2("cfgadd \"FC_DVT\", \"test5\""); $ssh->error and die "remote find command failed: $!" . $ssh->error; print "$out\n"; ($out,$err) = $ssh->capture2({stdin_data => 'yes'},"cfgsave"); $ssh->error and die "remote find command failed: $!" . $ssh->error; print "$out\n"; ($out,$err) = $ssh->capture2({stdin_data => 'yes'},"cfgenable \"FC_DVT +\""); $ssh->error and die "remote find command failed: $!" . $ssh->error; print "$out\n";
        Enable debugging in Net::OpenSSH in order to see what is going on:
        Net::OpenSSH::debug = -1;

        You never print the output in $out and $err before you stop your program. Maybe they contain useful information?