Hi,

I hope that SAN Admins find this helpful.

Whenever HBA WWNs are entered in Cisco SAN Switches on the command line prompt, A colon (:) character needs to be added at every second position in the WWN. Also, the WWN has to be lower case.

So in case you get a WWN like so - 10000000C9ABCDEF it needs to be converted to lower case and : needs to be added. The following script does this:

#!/usr/bin/perl use warnings; use strict; my $wwn = 0; until ( $wwn eq "q") { print "Enter the wwn or q to quit: "; chomp ($wwn=<STDIN>); my @wwn = unpack ("(a2)*", lc($wwn)); @wwn = join (":", @wwn); print "@wwn\n"; }
===============================================================================

Here is the updated version of the same script.

Here it adds ":" and lowercase. It also checks if the characters entered are Hex, if the length is correct and if any unwanted characters are given or not. In these cases, it takes you back to the prompt to enter the WWN.

It also does it the other way around, i.e. if you enter a WWN with ":", it removes them and does all the checks as mentioned above.

GrandFather and Not_a_Number thank you very much for your kind inputs.

I tried using the suggestions given by GrandFather in the other thread, but for some reason I could not tweak it enough to work.

Here is the script:

#!/usr/bin/perl use warnings; use strict; print "Enter a for lowercase and colons. b to do it the other way around. q to quit "; my $choice = 0; my $raw_wwn = 0; my $ripe_wwn = 0; my @array_wwn; my @ripe_wwn; chomp ($choice = <STDIN>); if ($choice eq "a") { until ( $raw_wwn eq "q") { print "Enter the wwn or q to quit: "; chomp ($raw_wwn=<STDIN>); if (length($raw_wwn)!=16 || $raw_wwn =~/[^0-9a-fA-F]/ ) { print "Invalid Length Or Incorrect Format\n"; } else { my @array_wwn = unpack ("(a2)*", lc($raw_wwn)); @ripe_wwn = join (":", @array_wwn); print "@ripe_wwn\n"; } } } elsif ($choice eq "b") { $raw_wwn =0; until ($raw_wwn eq "q") { print "Enter the wwn with : or q to quit: "; chomp ($raw_wwn=<STDIN>); if (length($raw_wwn)!=23||$raw_wwn=~/[^:a-fA-F0-9]/) { print "Invalid Length Or Incorrect Format\n"; } else { $raw_wwn=~ s/://g; $ripe_wwn = $raw_wwn; print lc($ripe_wwn), "\n"; } } }#closing for if choice =b elsif ($choice eq "q") { exit; }

And here is some test output:

[perlpetual@joesatch practice]$ perl wwn_final.pl Enter a for lowercase and colons. b to do it the other way around. q to quit a Enter the wwn or q to quit: 10000000C9ABCDEF 10:00:00:00:c9:ab:cd:ef Enter the wwn or q to quit: 10:00:00:00:c9:ab:cd:ef Invalid Length Or Incorrect Format Enter the wwn or q to quit: 10000000C9ABCDEG Invalid Length Or Incorrect Format Enter the wwn or q to quit: 10000000abcdefga Invalid Length Or Incorrect Format Enter the wwn or q to quit: 10000000abcdefab 10:00:00:00:ab:cd:ef:ab Enter the wwn or q to quit: q Invalid Length Or Incorrect Format [perlpetual@joesatch practice]$ perl wwn_final.pl Enter a for lowercase and colons. b to do it the other way around. q to quit b Enter the wwn with : or q to quit: 10:00:00:00:c9:ab:cd:ef 10000000c9abcdef Enter the wwn with : or q to quit: 10:00:00:00:c9:ab:cd:eg Invalid Length Or Incorrect Format Enter the wwn with : or q to quit: 10:00:00:00:c9:ab:cd:e Invalid Length Or Incorrect Format Enter the wwn with : or q to quit: 10000000c9abcdef Invalid Length Or Incorrect Format Enter the wwn with : or q to quit: q Invalid Length Or Incorrect Format [perlpetual@joesatch practice]$
Perlpetually Indebted To PerlMonks.

In reply to Script to convert HBA WWNs to lowercase and add ":"[Updated] by perl514

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.