http://www.perlmonks.org?node_id=1082812

Hi,

As an Storage Administrator who works on EMC Symmetrix Storage Array, many times, I have to extract a list of all the hosts connected to the storage array. This needs to be extracted by logging into the storage array and running a command like symmask -sid 12345 list logins, and then the hostnames are to be extracted from the list and stored in a text file. If hostnames are not reflecting, then the corresponding World Wide Name (WWN) of the Host HBA should be included in the list. To ensure dual or quadruple redunduncy, each host will show two paths or four paths, so the duplicates need to be removed and the host names need to be in Upper case. There are many such arrays, and a seperate file needs to be created for each of them.

Sometimes, the file has to be regenerated every few minutes due to some changes/requirements and the old file must be deleted, else wrong records will be captured. The script picks the array name from the command output stated earlier. This script is working fine on Redhat Linux 6.4 running Perl Version 5.10.1 and on Windows 2003 running Strawberry Perl version 5.18.2.2.

Hoping fellow EMC Administrators will find this script useful. Please note - I dont get to write scripts on a regular basis, so there's quite a lot of improvement that can be done with the script. If so, kindly let me know. Here's the script:

#!/usr/bin/perl use warnings; use strict; use Cwd 'abs_path'; my @hostnames; my ($identifier,$nodename); my $symmid; #The script will extact the servernames/pWWNs from the symmask list lo +gins output. while (<>) { if ($_=~/^Symmetrix ID/) { chomp ($symmid = (split /:\s+/)[1]); } next if $_ !~ /fibre/gi; ($identifier,$nodename)= (split /\s+/)[0,2]; if ($nodename eq "NULL") { $nodename=$identifier; push @hostnames, $nodename; } else { unshift @hostnames, uc $nodename; } } my $filename = "hostlist_${0}_${symmid}.txt"; unlink "$filename" if -e "$filename" && print "\nDeleting existing \"$ +filename\". A new one will be created.\n"; open(my $hostnamefile_fh, ">" ,"$filename" ) or die "Cannot open file. +$!.$^E"; my %repeated; my @uniqhostlist = grep {! $repeated{$_}++} sort @hostnames; print $hostnamefile_fh "Host List for Symmetrix ID: $symmid\n"; print $hostnamefile_fh "$_\n"foreach (@uniqhostlist); print "\n********************************************************* +********************************\n"; print "Please Check the file - [ " ,abs_path($filename), " ].\n"; print "NULLs are replaced with corresponding pWWNs.\n"; print "*********************************************************** +******************************\n";

Here's the test file that's fed to the script. The actual file will have much more entries than what's given below.

Symmetrix ID : 000190101234 Director Identification : FA-4A Director Port : 0 User-generated Logged + On Identifier Type Node Name Port Name FCID In + Fabric ---------------- ----- --------------------------------- ------ ------ + ------ 1000000002adf034 Fibre server011 switchport_0316 adcdef Yes + Yes 1000000003bd2134 Fibre server054 switchport_0928 adcdea Yes + Yes 1000000003bd216c Fibre server022 switchport_0315 adcdeb Yes + Yes 1000000003bd3054 Fibre server023 switchport_0319 adcde1 Yes + Yes 10000082d5316cd3 Fibre NULL NULL adcde2 No + Yes 1000000000805f5d Fibre sol02 switchport_058 adcde3 Yes + Yes 10000000009a1c5f Fibre server24 switchport_127 adcde4 Yes + Yes 10000000009ac25d Fibre server25 switchport_126 adcde5 Yes + Yes 10000000009ac25f Fibre NULL NULL adcde6 No + Yes Director Identification : FA-4A Director Port : 1 User-generated Logged + On Identifier Type Node Name Port Name FCID In + Fabric ---------------- ----- --------------------------------- ------ ------ + ------ 1000000002adf034 Fibre server011 switchport_0316 adcdef Yes + Yes 1000000003bd2134 Fibre server054 switchport_0928 adcdea Yes + Yes 1000000003bd2168 Fibre server055 switchport_0215 bd00dc Yes + Yes 1000000003bd3059 Fibre server056 switchport_0219 bd00ed Yes + Yes 10000082d5316cda Fibre NULL NULL 050022 N +o Yes 1000000000805f5b Fibre sol02 switchport_059 110a00 Yes + Yes 10000000009a1c5c Fibre server57 switchport_128 110700 Yes + Yes 10000000009ac251 Fibre server58 switchport_122 110800 Yes + Yes 10000000009ac25f Fibre NULL NULL adcde6 N +o Yes Director Identification : FA-4A Director Port : 0 User-generated Logged + On Identifier Type Node Name Port Name FCID In + Fabric ---------------- ----- --------------------------------- ------ ------ + ------ 1000000002adf034 Fibre server011 switchport_0316 adcdef Yes + Yes 1000000003bd2134 Fibre server054 switchport_0928 adcdea Yes + Yes 1000000003bd216c Fibre server087 switchport_0315 adcdeb Yes + Yes 1000000003bd3054 Fibre server088 switchport_0319 adcde1 Yes + Yes 10000082d5316cd3 Fibre NULL NULL adcde2 No + Yes 1000000000805f5d Fibre sol02 switchport_058 adcde3 Yes + Yes 10000000009a1c5f Fibre server89 switchport_127 adcde4 Yes + Yes 10000000009ac25d Fibre server90 switchport_126 adcde5 Yes + Yes 10000000009ac25f Fibre NULL NULL adcde6 No + Yes Director Identification : FA-4B Director Port : 0 User-generated Logged + On Identifier Type Node Name Port Name FCID In + Fabric ---------------- ----- --------------------------------- ------ ------ + ------ 1000000002adf034 Fibre server011 switchport_0316 adcdef Yes + Yes 1000000003bd2134 Fibre server054 switchport_0928 adcdea Yes + Yes 1000000003bd214a Fibre server001 switchport_0215 bd00dc Yes + Yes 1000000003bd304a Fibre server012 switchport_0219 bd00ed Yes + Yes 10000082d5316c4a Fibre NULL NULL 050022 No + Yes 1000000000805f4a Fibre sol02 switchport_059 110a00 Yes + Yes 10000000009a1c4a Fibre server13 switchport_128 110700 Yes + Yes 10000000009ac24a Fibre server14 switchport_122 110800 Yes + Yes 10000000009ac25f Fibre NULL NULL adcde6 No + Yes Director Identification : FA-4B Director Port : 1 User-generated Logged + On Identifier Type Node Name Port Name FCID In + Fabric ---------------- ----- --------------------------------- ------ ------ + ------ 1000000002adf034 Fibre server121 switchport_0316 adcdef Yes + Yes 1000000003bd2134 Fibre server154 switchport_0928 adcdea Yes + Yes 100000000abcd14a Fibre server101 switchport_0215 bd00dc Yes + Yes 100000000abcd04a Fibre server112 switchport_0219 bd00ed Yes + Yes 10000082dabcdc4a Fibre NULL NULL 050022 No + Yes 100000000abcdf4a Fibre server187 switchport_059 110a00 Yes + Yes 100000000abcdc4a Fibre server188 switchport_128 110700 Ye +s Yes 100000000abcd24a Fibre server189 switchport_122 110800 Ye +s Yes 10000000009ac25f Fibre NULL NULL adcde6 No + Yes

And here is the output:

C:\Users\pmu\Documents\perl\work>perl hostnames.pl test_list_logins.tx +t Deleting existing "hostlist_hostnames.pl_000190101234.txt". A new one +will be created. ********************************************************************** +******************* Please Check the file - [ C:\Users\pmu\Documents\perl\work\hostlist_ho +stnames.pl_000190101234.txt ]. NULLs are replaced with corresponding pWWNs. ********************************************************************** +******************* C:\Users\pmu\Documents\perl\work

And here's what the file - hostlist_hostnames.pl_000190101234.txt contains:

C:\Users\pmu\Documents\perl\work>more hostlist_hostnames.pl_0001901012 +34.txt Host List for Symmetrix ID: 000190101234 10000000009ac25f 10000082d5316c4a 10000082d5316cd3 10000082d5316cda 10000082dabcdc4a SERVER001 SERVER011 SERVER012 SERVER022 SERVER023 SERVER054 SERVER055 SERVER056 SERVER087 SERVER088 SERVER101 SERVER112 SERVER121 SERVER13 SERVER14 SERVER154 SERVER187 SERVER188 SERVER189 SERVER24 SERVER25 SERVER57 SERVER58 SERVER89 SERVER90 SOL02 C:\Users\pmu\Documents\perl\work>
-------------------------------------------------------------- Perspectum cognitio aeterna --------------------------------------------------------------