#!/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";