【问题标题】:perl brocade switch issue using Net::OpenSSH使用 Net::OpenSSH 的 perl brocade 交换机问题
【发布时间】:2015-10-20 11:59:29
【问题描述】:

我需要有关从远程系统配置 brocade switch 的帮助。我有使用Net::OpenSSH的示例代码

代码如下

#!/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 => join( "yes", "cfgsave" ) } );
$ssh->error and die "remote find command failed: $!" . $ssh->error;
print "$out\n";

( $out, $err ) = $ssh->capture2( { stdin_data => join( "yes", "cfgenable \"FC_DVT\"" ) } );
$ssh->error and die "remote find command failed: $!" . $ssh->error;
print "$out\n";

报错如下

[root@localhost jana]# ./switchconfig.pl
2015/07/29 23:59:57 performing ssh to the swicth
2015/07/29 23:59:58 listing zone on the switch 10.227.0.216 using zoneshow
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 23:59:59 zoneshow successful
2015/07/29 23:59:59 listing zone on the switch 10.227.0.216 using nsshow
{
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/30 00:00:00 nsshow successful
2015/07/30 00:00:03 create zone on the switch 10.227.0.216 using zonecreate

2015/07/30 00:00:04 zonecreate successful

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

我需要在cfgsavecfgenable 之后发送一个yes 作为使用yesno 选项的配置的开关提示saveenable 谢谢

使用调试输出发布

[root@localhost jana]# vi switchconfig.pl
[root@localhost jana]# ./switchconfig.pl
2015/07/30 00:18:18 performing ssh to the swicth
# open_ex: ['ssh','-V']
# io3 mloop, cin: 0, cout: 1, cerr: 0
# io3 fast, cin: 0, cout: 1, cerr: 0
# stdout, bytes read: 46 at offset 0
#> 4f 70 65 6e 53 53 48 5f 35 2e 33 70 31 2c 20 4f 70 65 6e 53 53 4c 20 31 2e 30 2e 30 2d 66 69 70 | OpenSSH_5.3p1, OpenSSL 1.0.0-fip
#> 73 20 32 39 20 4d 61 72 20 32 30 31 30 0a                                                       | s 29 Mar 2010.
# io3 fast, cin: 0, cout: 1, cerr: 0
# stdout, bytes read: 0 at offset 46
# leaving _io3()
# _waitpid(5385) => pid: 5385, rc: 0, err:
# OpenSSH verion is 5.3p1,
# ctl_path: /root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523, ctl_dir: /root/.libnet-openssh-perl/
# _is_secure_path(dir: /root/.libnet-openssh-perl, file mode: 16832, file uid: 0, euid: 0
# _is_secure_path(dir: /root, file mode: 16744, file uid: 0, euid: 0
# set_error(0 - 0)
# call args: ['ssh','-o','StrictHostKeyChecking=no','-o','ServerAliveInterval=30','-2MNx','-o','NumberOfPasswordPrompts=1','-o','PreferredAuthentications=keyboard-interactive,password','-S','/root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523','-l','admin','10.227.0.216','--']
# master state jumping from _STATE_START to _STATE_LOGIN
# file object not yet found at /root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523, state:_STATE_LOGIN
# file object not yet found at /root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523, state:_STATE_LOGIN
# file object not yet found at /root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523, state:_STATE_LOGIN
# file object not yet found at /root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523, state:_STATE_LOGIN
# file object not yet found at /root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523, state:_STATE_LOGIN
# file object not yet found at /root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523, state:_STATE_LOGIN
# tracer attached, ssh pid: 5386, tracer pid: 5387
# file object not yet found at /root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523, state:_STATE_LOGIN
# file object not yet found at /root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523, state:_STATE_LOGIN
# file object not yet found at /root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523, state:_STATE_LOGIN
# file object not yet found at /root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523, state:_STATE_LOGIN
# passwd/passphrase requested (admin@10.227.0.216's password:)
# file object not yet found at /root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523, state:_STATE_AWAITING_MUX
# file object not yet found at /root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523, state:_STATE_AWAITING_MUX
# file object found at /root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523
# master state jumping from _STATE_AWAITING_MUX to _STATE_RUNNING
# call args: ['ssh','-O','check','-T','-S','/root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523','-l','admin','10.227.0.216','--']
# open_ex: ['ssh','-O','check','-T','-S','/root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523','-l','admin','10.227.0.216','--']
# io3 mloop, cin: 0, cout: 1, cerr: 0
# io3 fast, cin: 0, cout: 1, cerr: 0
# stdout, bytes read: 27 at offset 0
#> 4d 61 73 74 65 72 20 72 75 6e 6e 69 6e 67 20 28 70 69 64 3d 35 33 38 36 29 0d 0a                | Master running (pid=5386)..
# io3 fast, cin: 0, cout: 1, cerr: 0
# stdout, bytes read: 0 at offset 27
# leaving _io3()
# _waitpid(5390) => pid: 5390, rc: 0, err:
2015/07/30 00:18:21 listing zone on the switch 10.227.0.216 using zoneshow
# call args: ['ssh','-S','/root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523','-l','admin','10.227.0.216','--','zoneshow']
# open_ex: ['ssh','-S','/root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523','-l','admin','10.227.0.216','--','zoneshow']
# io3 mloop, cin: 0, cout: 1, cerr: 1
# io3 fast, cin: 0, cout: 1, cerr: 1
# stdout, bytes read: 730 at offset 0
#> 44 65 66 69 6e 65 64 20 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e 3a 0a 20 63 66 67 3a 09 46 43 5f | Defined configuration:. cfg:.FC_
#> 44 56 54 09 4d 45 5a 5a 49 3b 20 4d 45 5a 5a 49 31 3b 20 74 65 73 74 31 0a 20 7a 6f 6e 65 3a 09 | DVT.MEZZI; MEZZI1; test1. zone:.
#> 4d 45 5a 5a 49 09 6d 65 7a 7a 69 31 3b 20 6d 65 7a 7a 69 32 3b 20 73 61 6e 62 6c 61 7a 65 0a 20 | MEZZI.mezzi1; mezzi2; sanblaze.
#> 7a 6f 6e 65 3a 09 4d 45 5a 5a 49 31 09 6d 65 7a 7a 69 33 3b 20 6d 65 7a 7a 69 34 3b 20 73 61 6e | zone:.MEZZI1.mezzi3; mezzi4; san
#> 62 6c 61 7a 65 0a 20 7a 6f 6e 65 3a 09 74 65 73 74 31 09 32 30 3a 30 30 3a 30 30 3a 31 31 3a 30 | blaze. zone:.test1.20:00:00:11:0
#> 64 3a 33 34 3a 35 36 3a 30 30 0a 20 7a 6f 6e 65 3a 09 76 69 6b 61 73 68 5f 65 6e 66 69 65 6c 64 | d:34:56:00. zone:.vikash_enfield
#> 09 0a 09 09 31 30 3a 30 30 3a 30 30 3a 30 30 3a 63 39 3a 61 31 3a 39 35 3a 61 61 3b 20 31 30 3a | ....10:00:00:00:c9:a1:95:aa; 10:
#> 30 30 3a 30 30 3a 30 30 3a 63 39 3a 61 31 3a 39 35 3a 61 62 3b 20 0a 09 09 32 30 3a 30 30 3a 30 | 00:00:00:c9:a1:95:ab; ...20:00:0
#> 30 3a 31 31 3a 30 64 3a 33 34 3a 35 36 3a 30 30 0a 20 61 6c 69 61 73 3a 09 6d 65 7a 7a 69 31 09 | 0:11:0d:34:56:00. alias:.mezzi1.
#> 31 30 3a 30 30 3a 30 30 3a 30 30 3a 63 39 3a 63 64 3a 63 63 3a 36 63 0a 20 61 6c 69 61 73 3a 09 | 10:00:00:00:c9:cd:cc:6c. alias:.
#> 6d 65 7a 7a 69 32 09 31 30 3a 30 30 3a 30 30 3a 30 30 3a 63 39 3a 63 64 3a 63 63 3a 36 64 0a 20 | mezzi2.10:00:00:00:c9:cd:cc:6d.
#> 61 6c 69 61 73 3a 09 6d 65 7a 7a 69 33 09 31 30 3a 30 30 3a 30 30 3a 39 30 3a 66 61 3a 32 65 3a | alias:.mezzi3.10:00:00:90:fa:2e:
#> 64 64 3a 39 66 0a 20 61 6c 69 61 73 3a 09 6d 65 7a 7a 69 34 09 31 30 3a 30 30 3a 30 30 3a 39 30 | dd:9f. alias:.mezzi4.10:00:00:90
#> 3a 66 61 3a 32 65 3a 64 64 3a 61 30 0a 20 61 6c 69 61 73 3a 09 73 61 6e 62 6c 61 7a 65 09 0a 09 | :fa:2e:dd:a0. alias:.sanblaze...
#> 09 32 30 3a 30 31 3a 30 30 3a 31 31 3a 30 64 3a 33 34 3a 35 37 3a 30 30 0a 0a 45 66 66 65 63 74 | .20:01:00:11:0d:34:57:00..Effect
#> 69 76 65 20 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e 3a 0a 20 63 66 67 3a 09 46 43 5f 44 56 54 09 | ive configuration:. cfg:.FC_DVT.
#> 0a 20 7a 6f 6e 65 3a 09 4d 45 5a 5a 49 09 31 30 3a 30 30 3a 30 30 3a 30 30 3a 63 39 3a 63 64 3a | . zone:.MEZZI.10:00:00:00:c9:cd:
#> 63 63 3a 36 63 0a 09 09 31 30 3a 30 30 3a 30 30 3a 30 30 3a 63 39 3a 63 64 3a 63 63 3a 36 64 0a | cc:6c...10:00:00:00:c9:cd:cc:6d.
#> 09 09 32 30 3a 30 31 3a 30 30 3a 31 31 3a 30 64 3a 33 34 3a 35 37 3a 30 30 0a 20 7a 6f 6e 65 3a | ..20:01:00:11:0d:34:57:00. zone:
#> 09 4d 45 5a 5a 49 31 09 31 30 3a 30 30 3a 30 30 3a 39 30 3a 66 61 3a 32 65 3a 64 64 3a 39 66 0a | .MEZZI1.10:00:00:90:fa:2e:dd:9f.
#> 09 09 31 30 3a 30 30 3a 30 30 3a 39 30 3a 66 61 3a 32 65 3a 64 64 3a 61 30 0a 09 09 32 30 3a 30 | ..10:00:00:90:fa:2e:dd:a0...20:0
#> 31 3a 30 30 3a 31 31 3a 30 64 3a 33 34 3a 35 37 3a 30 30 0a 20 7a 6f 6e 65 3a 09 74 65 73 74 31 | 1:00:11:0d:34:57:00. zone:.test1
#> 09 32 30 3a 30 30 3a 30 30 3a 31 31 3a 30 64 3a 33 34 3a 35 36 3a 30 30 0a 0a                   | .20:00:00:11:0d:34:56:00..
# io3 fast, cin: 0, cout: 1, cerr: 1
# stdout, bytes read: 0 at offset 730
# stderr, bytes read: 0
# leaving _io3()
# _waitpid(5391) => pid: 5391, rc: 0, err:
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/30 00:18:22 zoneshow successful
2015/07/30 00:18:22 listing zone on the switch 10.227.0.216 using nsshow
# call args: ['ssh','-S','/root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523','-l','admin','10.227.0.216','--','nsshow']
# open_ex: ['ssh','-S','/root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523','-l','admin','10.227.0.216','--','nsshow']
# io3 mloop, cin: 0, cout: 1, cerr: 1
# io3 fast, cin: 0, cout: 1, cerr: 1
# stdout, bytes read: 1568 at offset 0
#> 7b 0a 20 54 79 70 65 20 50 69 64 20 20 20 20 43 4f 53 20 20 20 20 20 50 6f 72 74 4e 61 6d 65 20 | {. Type Pid    COS     PortName
#> 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 4e 6f 64 65 4e 61 6d 65 20 20 20 20 20 20 20 20 20 |                NodeName
#> 20 20 20 20 20 20 20 20 54 54 4c 28 73 65 63 29 0a 20 4e 20 20 20 20 30 31 30 37 30 30 3b 20 20 |         TTL(sec). N    010700;
#> 20 20 20 20 33 3b 35 30 3a 30 61 3a 30 39 3a 38 34 3a 38 38 3a 65 64 3a 36 36 3a 64 34 3b 35 30 |     3;50:0a:09:84:88:ed:66:d4;50
#> 3a 30 61 3a 30 39 3a 38 30 3a 38 38 3a 65 64 3a 36 36 3a 64 34 3b 20 6e 61 0a 20 20 20 20 46 43 | :0a:09:80:88:ed:66:d4; na.    FC
#> 34 73 3a 20 46 43 50 20 5b 4e 45 54 41 50 50 20 20 4c 55 4e 20 20 20 20 20 20 20 20 20 20 20 20 | 4s: FCP [NETAPP  LUN
#> 20 37 33 36 30 5d 0a 20 20 20 20 46 61 62 72 69 63 20 50 6f 72 74 20 4e 61 6d 65 3a 20 32 30 3a |  7360].    Fabric Port Name: 20:
#> 30 37 3a 30 30 3a 30 35 3a 33 33 3a 64 34 3a 30 36 3a 34 64 20 0a 20 20 20 20 50 65 72 6d 61 6e | 07:00:05:33:d4:06:4d .    Perman
#> 65 6e 74 20 50 6f 72 74 20 4e 61 6d 65 3a 20 35 30 3a 30 61 3a 30 39 3a 38 34 3a 38 38 3a 65 64 | ent Port Name: 50:0a:09:84:88:ed
#> 3a 36 36 3a 64 34 0a 20 20 20 20 50 6f 72 74 20 49 6e 64 65 78 3a 20 37 0a 20 20 20 20 53 68 61 | :66:d4.    Port Index: 7.    Sha
#> 72 65 20 41 72 65 61 3a 20 4e 6f 0a 20 20 20 20 44 65 76 69 63 65 20 53 68 61 72 65 64 20 69 6e | re Area: No.    Device Shared in
#> 20 4f 74 68 65 72 20 41 44 3a 20 4e 6f 0a 20 20 20 20 52 65 64 69 72 65 63 74 3a 20 4e 6f 20 0a |  Other AD: No.    Redirect: No .
#> 20 20 20 20 50 61 72 74 69 61 6c 3a 20 4e 6f 0a 20 20 20 20 4c 53 41 4e 3a 20 4e 6f 0a 20 4e 20 |     Partial: No.    LSAN: No. N
#> 20 20 20 30 31 30 61 30 30 3b 20 20 20 20 20 20 33 3b 31 30 3a 30 30 3a 30 30 3a 39 30 3a 66 61 |    010a00;      3;10:00:00:90:fa
#> 3a 32 65 3a 64 64 3a 39 66 3b 32 30 3a 30 30 3a 30 30 3a 39 30 3a 66 61 3a 32 65 3a 64 64 3a 39 | :2e:dd:9f;20:00:00:90:fa:2e:dd:9
#> 66 3b 20 6e 61 0a 20 20 20 20 46 43 34 73 3a 20 49 50 46 43 20 46 43 50 20 0a 20 20 20 20 50 6f | f; na.    FC4s: IPFC FCP .    Po
#> 72 74 53 79 6d 62 3a 20 5b 33 34 5d 20 22 45 6d 75 6c 65 78 20 50 50 4e 2d 31 30 3a 30 30 3a 30 | rtSymb: [34] "Emulex PPN-10:00:0
#> 30 3a 39 30 3a 66 61 3a 32 65 3a 64 64 3a 39 66 22 0a 20 20 20 20 4e 6f 64 65 53 79 6d 62 3a 20 | 0:90:fa:2e:dd:9f".    NodeSymb:
#> 5b 33 37 5d 20 22 45 6d 75 6c 65 78 20 37 31 30 31 36 38 34 20 46 56 31 30 2e 36 2e 31 36 38 2e | [37] "Emulex 7101684 FV10.6.168.
#> 30 20 44 56 33 2e 30 2e 30 32 20 22 0a 20 20 20 20 46 61 62 72 69 63 20 50 6f 72 74 20 4e 61 6d | 0 DV3.0.02 ".    Fabric Port Nam
#> 65 3a 20 32 30 3a 30 61 3a 30 30 3a 30 35 3a 33 33 3a 64 34 3a 30 36 3a 34 64 20 0a 20 20 20 20 | e: 20:0a:00:05:33:d4:06:4d .
#> 50 65 72 6d 61 6e 65 6e 74 20 50 6f 72 74 20 4e 61 6d 65 3a 20 31 30 3a 30 30 3a 30 30 3a 39 30 | Permanent Port Name: 10:00:00:90
#> 3a 66 61 3a 32 65 3a 64 64 3a 39 66 0a 20 20 20 20 50 6f 72 74 20 49 6e 64 65 78 3a 20 31 30 0a | :fa:2e:dd:9f.    Port Index: 10.
#> 20 20 20 20 53 68 61 72 65 20 41 72 65 61 3a 20 4e 6f 0a 20 20 20 20 44 65 76 69 63 65 20 53 68 |     Share Area: No.    Device Sh
#> 61 72 65 64 20 69 6e 20 4f 74 68 65 72 20 41 44 3a 20 4e 6f 0a 20 20 20 20 52 65 64 69 72 65 63 | ared in Other AD: No.    Redirec
#> 74 3a 20 4e 6f 20 0a 20 20 20 20 50 61 72 74 69 61 6c 3a 20 4e 6f 0a 20 20 20 20 4c 53 41 4e 3a | t: No .    Partial: No.    LSAN:
#> 20 4e 6f 0a 20 4e 20 20 20 20 30 31 30 62 30 30 3b 20 20 20 20 32 2c 33 3b 32 30 3a 30 30 3a 30 |  No. N    010b00;    2,3;20:00:0
#> 30 3a 31 31 3a 30 64 3a 33 34 3a 35 36 3a 30 30 3b 32 30 3a 30 30 3a 30 30 3a 31 31 3a 30 64 3a | 0:11:0d:34:56:00;20:00:00:11:0d:
#> 33 34 3a 35 36 3a 30 30 3b 20 6e 61 0a 20 20 20 20 46 43 34 73 3a 20 46 43 50 20 0a 20 20 20 20 | 34:56:00; na.    FC4s: FCP .
#> 50 6f 72 74 53 79 6d 62 3a 20 5b 32 32 5d 20 22 53 41 4e 42 6c 61 7a 65 20 46 43 20 50 6f 72 74 | PortSymb: [22] "SANBlaze FC Port
#> 20 54 61 72 67 30 22 0a 20 20 20 20 46 61 62 72 69 63 20 50 6f 72 74 20 4e 61 6d 65 3a 20 32 30 |  Targ0".    Fabric Port Name: 20
#> 3a 30 62 3a 30 30 3a 30 35 3a 33 33 3a 64 34 3a 30 36 3a 34 64 20 0a 20 20 20 20 50 65 72 6d 61 | :0b:00:05:33:d4:06:4d .    Perma
#> 6e 65 6e 74 20 50 6f 72 74 20 4e 61 6d 65 3a 20 32 30 3a 30 30 3a 30 30 3a 31 31 3a 30 64 3a 33 | nent Port Name: 20:00:00:11:0d:3
#> 34 3a 35 36 3a 30 30 0a 20 20 20 20 50 6f 72 74 20 49 6e 64 65 78 3a 20 31 31 0a 20 20 20 20 53 | 4:56:00.    Port Index: 11.    S
#> 68 61 72 65 20 41 72 65 61 3a 20 4e 6f 0a 20 20 20 20 44 65 76 69 63 65 20 53 68 61 72 65 64 20 | hare Area: No.    Device Shared
#> 69 6e 20 4f 74 68 65 72 20 41 44 3a 20 4e 6f 0a 20 20 20 20 52 65 64 69 72 65 63 74 3a 20 4e 6f | in Other AD: No.    Redirect: No
#> 20 0a 20 20 20 20 50 61 72 74 69 61 6c 3a 20 4e 6f 0a 20 20 20 20 4c 53 41 4e 3a 20 4e 6f 0a 20 |  .    Partial: No.    LSAN: No.
#> 4e 20 20 20 20 30 31 30 65 30 30 3b 20 20 20 20 32 2c 33 3b 32 30 3a 30 31 3a 30 30 3a 31 31 3a | N    010e00;    2,3;20:01:00:11:
#> 30 64 3a 33 34 3a 35 37 3a 30 30 3b 32 30 3a 30 31 3a 30 30 3a 31 31 3a 30 64 3a 33 34 3a 35 37 | 0d:34:57:00;20:01:00:11:0d:34:57
#> 3a 30 30 3b 20 6e 61 0a 20 20 20 20 46 43 34 73 3a 20 46 43 50 20 0a 20 20 20 20 50 6f 72 74 53 | :00; na.    FC4s: FCP .    PortS
#> 79 6d 62 3a 20 5b 32 32 5d 20 22 53 41 4e 42 6c 61 7a 65 20 46 43 20 50 6f 72 74 20 54 61 72 67 | ymb: [22] "SANBlaze FC Port Targ
#> 30 22 0a 20 20 20 20 46 61 62 72 69 63 20 50 6f 72 74 20 4e 61 6d 65 3a 20 32 30 3a 30 65 3a 30 | 0".    Fabric Port Name: 20:0e:0
#> 30 3a 30 35 3a 33 33 3a 64 34 3a 30 36 3a 34 64 20 0a 20 20 20 20 50 65 72 6d 61 6e 65 6e 74 20 | 0:05:33:d4:06:4d .    Permanent
#> 50 6f 72 74 20 4e 61 6d 65 3a 20 32 30 3a 30 31 3a 30 30 3a 31 31 3a 30 64 3a 33 34 3a 35 37 3a | Port Name: 20:01:00:11:0d:34:57:
#> 30 30 0a 20 20 20 20 50 6f 72 74 20 49 6e 64 65 78 3a 20 31 34 0a 20 20 20 20 53 68 61 72 65 20 | 00.    Port Index: 14.    Share
#> 41 72 65 61 3a 20 4e 6f 0a 20 20 20 20 44 65 76 69 63 65 20 53 68 61 72 65 64 20 69 6e 20 4f 74 | Area: No.    Device Shared in Ot
#> 68 65 72 20 41 44 3a 20 4e 6f 0a 20 20 20 20 52 65 64 69 72 65 63 74 3a 20 4e 6f 20 0a 20 20 20 | her AD: No.    Redirect: No .
#> 20 50 61 72 74 69 61 6c 3a 20 4e 6f 0a 20 20 20 20 4c 53 41 4e 3a 20 4e 6f 0a 54 68 65 20 4c 6f |  Partial: No.    LSAN: No.The Lo
#> 63 61 6c 20 4e 61 6d 65 20 53 65 72 76 65 72 20 68 61 73 20 34 20 65 6e 74 72 69 65 73 20 7d 0a | cal Name Server has 4 entries }.
# io3 fast, cin: 0, cout: 1, cerr: 1
# stdout, bytes read: 0 at offset 1568
# stderr, bytes read: 0
# leaving _io3()
# _waitpid(5392) => pid: 5392, rc: 0, err:
{
 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/30 00:18:23 nsshow successful
2015/07/30 00:18:26 create zone on the switch 10.227.0.216 using zonecreate
# call args: ['ssh','-S','/root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523','-l','admin','10.227.0.216','--','zonecreate "test5", " 20:01:00:11:0d:34:57:00" ']
# open_ex: ['ssh','-S','/root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523','-l','admin','10.227.0.216','--','zonecreate "test5", " 20:01:00:11:0d:34:57:00" ']
# io3 mloop, cin: 0, cout: 1, cerr: 1
# io3 fast, cin: 0, cout: 1, cerr: 1
# stdout, bytes read: 0 at offset 0
# stderr, bytes read: 0
# leaving _io3()
# _waitpid(5393) => pid: 5393, rc: 0, err:

2015/07/30 00:18:27 zonecreate successful
# call args: ['ssh','-S','/root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523','-l','admin','10.227.0.216','--','cfgadd "FC_DVT", "test5"']
# open_ex: ['ssh','-S','/root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523','-l','admin','10.227.0.216','--','cfgadd "FC_DVT", "test5"']
# io3 mloop, cin: 0, cout: 1, cerr: 1
# io3 fast, cin: 0, cout: 1, cerr: 1
# stdout, bytes read: 0 at offset 0
# stderr, bytes read: 0
# leaving _io3()
# _waitpid(5394) => pid: 5394, rc: 0, err:

# call args: ['ssh','-S','/root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523','-l','admin','10.227.0.216','--']
# open_ex: ['ssh','-S','/root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523','-l','admin','10.227.0.216','--']
# io3 mloop, cin: 1, cout: 1, cerr: 1
# io3 fast, cin: 1, cout: 1, cerr: 1
# stdin, bytes written: 7
#> 63 66 67 73 61 76 65                                                                            | cfgsave
# io3 mloop, cin: 0, cout: 1, cerr: 1
# io3 fast, cin: 0, cout: 1, cerr: 1
# stderr, bytes read: 72
# io3 fast, cin: 0, cout: 1, cerr: 1
# stdout, bytes read: 369 at offset 0
#> 59 6f 75 20 61 72 65 20 61 62 6f 75 74 20 74 6f 20 73 61 76 65 20 74 68 65 20 44 65 66 69 6e 65 | You are about to save the Define
#> 64 20 7a 6f 6e 69 6e 67 20 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e 2e 20 54 68 69 73 0a 61 63 74 | d zoning configuration. This.act
#> 69 6f 6e 20 77 69 6c 6c 20 6f 6e 6c 79 20 73 61 76 65 20 74 68 65 20 63 68 61 6e 67 65 73 20 6f | ion will only save the changes o
#> 6e 20 44 65 66 69 6e 65 64 20 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e 2e 0a 49 66 20 74 68 65 20 | n Defined configuration..If the
#> 75 70 64 61 74 65 20 69 6e 63 6c 75 64 65 73 20 63 68 61 6e 67 65 73 20 74 6f 20 6f 6e 65 20 6f | update includes changes to one o
#> 72 20 6d 6f 72 65 20 74 72 61 66 66 69 63 20 69 73 6f 6c 61 74 69 6f 6e 0a 7a 6f 6e 65 73 2c 20 | r more traffic isolation.zones,
#> 79 6f 75 20 6d 75 73 74 20 69 73 73 75 65 20 74 68 65 20 27 63 66 67 65 6e 61 62 6c 65 27 20 63 | you must issue the 'cfgenable' c
#> 6f 6d 6d 61 6e 64 20 66 6f 72 20 74 68 65 20 63 68 61 6e 67 65 73 0a 74 6f 20 74 61 6b 65 20 65 | ommand for the changes.to take e
#> 66 66 65 63 74 2e 0a 44 6f 20 79 6f 75 20 77 61 6e 74 20 74 6f 20 73 61 76 65 20 74 68 65 20 44 | ffect..Do you want to save the D
#> 65 66 69 6e 65 64 20 7a 6f 6e 69 6e 67 20 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 6f 6e 6c 79 | efined zoning configuration only
#> 3f 20 20 28 79 65 73 2c 20 79 2c 20 6e 6f 2c 20 6e 29 3a 20 5b 6e 6f 5d 20 0a 0a 4f 70 65 72 61 | ?  (yes, y, no, n): [no] ..Opera
#> 74 69 6f 6e 20 63 61 6e 63 65 6c 65 64 2e 2e 2e 0a                                              | tion canceled....
# io3 fast, cin: 0, cout: 1, cerr: 1
# stdout, bytes read: 0 at offset 369
# stderr, bytes read: 0
# leaving _io3()
# _waitpid(5395) => pid: 5395, rc: 63488, err:
# set_error(5 - child exited with code 248)
remote find command failed: child exited with code 248 at ./switchconfig.pl line 46.
# DESTROY(Net::OpenSSH=HASH(0x1c89610), pid: 5386)
# sending exit control to master
# call args: ['ssh','-O','exit','-T','-S','/root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523','-l','admin','10.227.0.216','--']
# open_ex: ['ssh','-O','exit','-T','-S','/root/.libnet-openssh-perl/admin-10.227.0.216-5384-5523','-l','admin','10.227.0.216','--']
# io3 mloop, cin: 0, cout: 1, cerr: 0
# io3 fast, cin: 0, cout: 1, cerr: 0
# stdout, bytes read: 20 at offset 0
#> 45 78 69 74 20 72 65 71 75 65 73 74 20 73 65 6e 74 2e 0d 0a                                     | Exit request sent...
# io3 fast, cin: 0, cout: 1, cerr: 0
# stdout, bytes read: 0 at offset 20
# leaving _io3()
# _waitpid(5396) => pid: 5396, rc: 0, err:
# set_error(1 - aborted)
# master state jumping from _STATE_RUNNING to _STATE_KILLING
# killing master
# _master_kill: 5386
# waitpid(master: 5386) => pid: 0, rc:
# waitpid(master: 5386) => pid: 5386, rc: Interrupted system call
# master state jumping from _STATE_KILLING to _STATE_GONE

【问题讨论】:

  • 我不认为join 做你期望它做的事情,而是join( "yes", "cfgsave" ) 返回字符串"cfgsave"(因为它试图在每个元素之间放置一个"yes"一个元素列表)。也许你想join("\n", "cfgsave", "yes", "")? (我不会将此作为答案发布,因为我不确定它之后是否会真正起作用,但这似乎是您的问题)

标签: perl


【解决方案1】:

问题已解决,不是我解决的,而是 perlmonks 解决的

发布答案

#!/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);
$Net::OpenSSH::debug = -1;


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 \"test15\", \" 20:01:00:1
+1: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\", \"test15\"" );
$ssh->error and die "remote find command failed: $!" . $ssh->error;
print "$out\n";

( $out, $err ) = $ssh->capture2( { stdin_data =>"yes\n"}, "cfgsave"  )
+;
$ssh->error and die "remote find command failed: $!" . $ssh->error;
print "$out\n";

( $out, $err ) = $ssh->capture2( { stdin_data =>"yes\n"},"cfgenable \"
+FC_DVT\"");
$ssh->error and die "remote find command failed: $!" . $ssh->error;
print "$out\n";
[download]  

【讨论】:

    猜你喜欢
    • 2014-02-21
    • 2012-09-20
    • 2016-08-21
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    • 2012-11-05
    • 2010-11-21
    • 2016-09-13
    相关资源
    最近更新 更多