{"id":463,"date":"2022-11-03T08:34:43","date_gmt":"2022-11-03T08:34:43","guid":{"rendered":"https:\/\/www.aixperts.co.uk\/?p=463"},"modified":"2022-11-03T08:37:01","modified_gmt":"2022-11-03T08:37:01","slug":"script-to-change-wwpns-in-lpar-profile","status":"publish","type":"post","link":"https:\/\/www.aixperts.co.uk\/?p=463","title":{"rendered":"Script to change WWPNS in LPAR profile"},"content":{"rendered":"\n<p>This is a script to interactively change WWPNs on adapters in an IBM POWER\/Power systems LPAR profile. This is useful if you have to re-create adapters or even whole profiles as the HMC GUI does not allow you to set or change WWPNs, and the HMC command line is not exactly elegant.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Copyright AIXperts Consultancy ltd, Henrik Morsing - November 2022\n\necho\necho \"You are about to write new WWPNs to the adapters for this profile. Please backup the profile first\"\necho\n\n# Prompt for hmc and host\n\nprintf \"Please enter HMC to connect to: \"; read hmc\nprintf \"Please enter host to change: \"; read host\necho\n\n# Find LPAR and system names\nwhile read sys\ndo\n   #echo \"Checking system \"${sys}\n   lpar=\"$(echo $(ssh -n ${hmc} lssyscfg -r lpar -m ${sys} -F name) | tr ' ' '\\n' | grep ${host})\"\n   if &#91;&#91; ${lpar} != \"\" ]]\n   then\n      #echo \"Break-out\"\n      export system=${sys}\n      break\n   fi\ndone &lt;&lt;&lt; \"$(ssh ${hmc} 'lssyscfg -r sys -F name')\"\n\n# Find profile name\nprofile_name=\"$(echo $(ssh ${hmc} lssyscfg -r prof -m ${system} --filter \\\"lpar_names=${lpar}\\\" -F name) | cut -f1 -d' ')\"\n\n# Find WWPNs\ntypeset -A value        # For WWPNs\ntypeset -i f=0          # Counter for adapter\ntypeset -i field=1      # Counter for adapter\nvalue&#91;${f}]=\"kjfhkes\"   # Inital, non-empty value\n\n# Define some arrays to read output values into\ntypeset -A adapter_id\ntypeset -A rlpar_id\ntypeset -A rlpar_name\ntypeset -A rslot_no\n\n# Let's fetch the output from the HMC\ncmd_out=\"$(ssh ${hmc} lssyscfg -m ${system} -r prof --filter \\\"lpar_names=${lpar},profile_names=${profile_name}\\\" -F virtual_fc_adapters)\"\n\n# Loop to read every adapter output\nwhile &#91;&#91; -n ${value&#91;${f}]} ]]\ndo\n   f+=1\n   # Read values for each adapter in turn into the arrays\n   echo ${cmd_out} | tr -d '\"' | cut -d, -f${field},$(( ${field}+1 )) | tr '\/' ' '| read adapter_id&#91;${f}] client rlpar_id&#91;${f}] rlpar_name&#91;${f}] rslot_no&#91;${f}] value&#91;${f}] req\n\n   field+=2\ndone\n\n# Before starting this loop, start building up a command to submit\ncmd=\"ssh ${hmc} chsyscfg -r prof -m ${system} --force -i \\\"lpar_name=${lpar}, name=${profile_name}, \\\\\\\"virtual_fc_adapters=\"\n\nf=1     # Adapter counter\n\nwhile &#91;&#91; -n ${value&#91;${f}]} ]]\ndo\n   printf \"Enter new WWPN or hit &lt;ENTER&gt; to keep WWPN &#91;\"${value&#91;${f}]}\"]: \"; read wwpns_input\n\n   if &#91;&#91; \"${wwpns_input}\" == \"\" ]]\n   then\n\n      cmd_build=${cmd}\\\\\\\"\\\\\\\"${adapter_id&#91;${f}]}\/client\/${rlpar_id&#91;${f}]}\/${rlpar_name&#91;${f}]}\/${rslot_no&#91;${f}]}\/${value&#91;${f}]}\/0\\\\\\\"\\\\\\\",\n      cmd=${cmd_build}\n\n      # Increment f\n      f+=1\n\n   elif &#91;&#91; \"${wwpns_input}\" =~ &#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f],&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f]&#91;0-9a-f] ]]\n   then\n      value&#91;${f}]=${wwpns_input}\n\n      cmd_build=${cmd}\\\\\\\"\\\\\\\"${adapter_id&#91;${f}]}\/client\/${rlpar_id&#91;${f}]}\/${rlpar_name&#91;${f}]}\/${rslot_no&#91;${f}]}\/${value&#91;${f}]}\/0\\\\\\\"\\\\\\\",\n      cmd=${cmd_build}\n\n      # Increment f\n      f+=1\n\n   else\n      echo \"Invalid entry, please try again\"\n   fi\ndone\n\n# Now, tidy-up end of command\ncmd_end=$(echo ${cmd_build} | sed 's\/,$\/\/')     # Remove trailing comma\ncmd_complete=${cmd_end}\\\\\\\"\\\"\\                  # Finish off quites\n\necho\necho \"Running: \"${cmd_complete}\n\n${cmd_complete}\n\nexit 0\n<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a script to interactively change WWPNs on adapters in an IBM POWER\/Power systems LPAR profile. This is useful if you have to re-create adapters or even whole profiles as the HMC GUI does not allow you to set &hellip; <a href=\"https:\/\/www.aixperts.co.uk\/?p=463\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,156,147,148],"tags":[7,152,153,154,155,151,150],"class_list":["post-463","post","type-post","status-publish","format-standard","hentry","category-aix","category-hmc","category-ibm-power","category-scripting","tag-aix","tag-fibre-adapter","tag-hmc","tag-hmc-scripting","tag-lpar-profile","tag-vfc","tag-wwpns"],"_links":{"self":[{"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/463","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=463"}],"version-history":[{"count":2,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/463\/revisions"}],"predecessor-version":[{"id":466,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/463\/revisions\/466"}],"wp:attachment":[{"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}