use strict; use warnings; #use Data::Dumper; my $lsdev = "/usr/sbin/lsdev -c tape"; my $lsattr = "/usr/sbin/lsattr -El"; my (@rmts, %wwns, $rmtkey, @input2, @fileinput); sub _compare_match_WWPN { die "no parameter!\n" unless @_; my ($w_ref) = @_; my (@w) = @{ $w_ref }; open (LSDEV, "-|", $lsdev) or die "'lsdev' was not opened $!\n"; for my $t () { push @rmts, +(split(" ", $t, 0))[0]; } for my $r (@rmts) { push @{ $wwns{$r}}, +(split(/\s+|0x/, `$lsattr $r -a node_name`, 0))[2]; push @{ $wwns{$r}}, +(split(/\s+|0x/, `$lsattr $r -a ww_name`, 0))[2]; } OUTER: foreach my $rmtkey (sort keys %wwns) { for my $indx ( 0 .. $#{$wwns{$rmtkey}} ) { for my $name ( @w ) { if ( $name =~ /^$wwns{$rmtkey}[$indx]$/i ) { print "Found '${name}' that belongs to $rmtkey\n"; next OUTER; } ### HERE IS WHERE I TRIED ELSE, etc. CONDITIONS ### } } } return; } ##-- MAIN --## print "\nTSM Device ID Search\nPlease enter cli or file: "; while ( chomp ( my $input = lc(<>) ) ) { last if $input =~ /\s+$/; if ( $input eq "cli" ) { INNER: print "\nEnter your wwns to search for? More than one, comma seperated: ---> "; while ( chomp ( my $input2 = lc(<>) ) ) { last if $input2 !~ /\w+/; @input2 = split(/,|\s+/, $input2); _compare_match_WWPN( \@input2 ); print "\nDo you want to restart this search? ---> "; chomp ( my $input3 = lc(<>) ); goto INNER if $input3 eq "yes" or $input3 eq "y"; exit 0; } } elsif ( $input eq "file" ) { INNER2: print "\nEnter the fullpath+filename, Enter to end? ---> "; while ( chomp ( my $input4 = lc(<>) ) ) { open ( F, "+<", $input4 ) or die "'$input4' file was not found/opened $!\n"; while () { push @fileinput, split(/,|\s+/, lc($_)); } _compare_match_WWPN( \@fileinput ); print "\nDo you want to restart this search? ---> "; chomp ( my $input5 = lc(<>) ); goto INNER2 if $input5 eq "yes" or $input5 eq "y"; exit 0; } } else { warn "\nI need input of file or cli, exiting.\n$!\n"; die; } } _OUTPUT_ # perl tsm_IDstorage_devs.pl TSM Device ID Search Please enter cli or file: cli Enter your wwns to search for? More than one, comma seperated: ---> 21000024ff66941c,2009000g123456ff Found '21000024ff66941c' that belongs to rmt137 Found '21000024ff66941c' that belongs to rmt138 Found '21000024ff66941c' that belongs to rmt139 Found '21000024ff66941c' that belongs to rmt140 Found '21000024ff66941c' that belongs to rmt141 Found '21000024ff66941c' that belongs to rmt142 Found '21000024ff66941c' that belongs to smc14 _DATA_STRUCTURE_ $VAR1 = { 'rmt54' => [ '500143802483d27c', '500143802483d27d' ], 'rmt42' => [ '500143802483cfe2', '500143802483cfe5' ], };