10 Replies Latest reply on Sep 16, 2015 6:26 PM by Kai Hintze

    Basic NSH script for bulk decommissions

    Laurelyn Collins

      I'm trying to use NSH to decommission a list of retired servers.  I created batch-decom.nsh as follows:

       

      SERVERLIST=`cat "servers.txt"`

      for server in $SERVERLIST

      do

          blcli -v myusername Server decommissionServer $server

      done

       

      Problem:

       

      After running this, if I look for the decommissioned servers in the BL Console GUI, they are not found, which is what I want.  However, if I run agentinfo $server, I still get results for the supposedly decommed servers, even if I exit the NSH console and start a new session.

       

      Question:

      Are the severs actually getting decommed?  Do I need to do some kind of data refresh on the NSH console?

       

      Problem 2:

      I don't get any output on the command until the whole file has been run, and when I do, it's similar to this:

       

      voidvoidvoidCommand execution failed.  Device blah1 not found.Command execution failed.

        Device blah2 not found.Command execution failed.  Device blah3 not

      found. etc.

       

      Question 2:

      How can I get more useful output that will show me which devices were successfully decommissioned, not found, and so on?

       

      Thanks in advance.

      -Laurelyn

        • 1. Re: Basic NSH script for bulk decommissions
          Bill Robinson

          if they are not showing in bsa, then they are decomissioned.  decomissioning does not uninstall anything, it just deregisters it from the appserver.  so you can still use nsh to talk to it as along as the rscd service is running.

           

          you should be able to create a report in bdssa that would list servers that were decomissioned.  not sure about 'not found' - if it doesn't exist in bsa, then you can't report anything about it.

          1 of 1 people found this helpful
          • 2. Re: Basic NSH script for bulk decommissions
            Barry McQuillan

            Hi Laurelyn,

             

            Bill has addressed Question 1, so I'll take a stab at the rest.

            Problem 1:

            It really depends what your end goal is here. So I'll try and cover most possibilities to remove the possibility of connecting to a decommed server.

             

            If the requirement is to remove the agent from the target, then you will need to execute a RSCD Agent silent uninstall on each target .

            If you merely want to prevent connectivity using NSH then you can just stop the rscd agent.

             

            Remembering that you will not get a successful return once it is removed/stopped.

             

            Problem 2:

            Unfortunately you won't get any output from the NSHJob until it completes.  There are a few ways around this depending on the desired result:

            • You could echo the result out to a logfile inside the loop and track it by tailing the logfile.
            • You can echo the info from your script and it will show up in the NSHJob log on completion.

            Depending on the number of servers you want to execute against you might want to use the NSH Performance commands as they provide a significant time saving in execution time.
            I would use something like the following:

            SERVERLIST=`cat "servers.txt"`
            # setOption values are only required if you are executing the script from the command line.
            #blcli_setoption roleName BLAdmin
            #blcli_setoption serviceProfileName myusername
            blcli_connect

            for SERVER in $SERVERLIST
            do
            Decommissioning ${SERVER}
                blcli_execute Server decommissionServer ${SERVER} 1>/dev/null 
            #this should stop "void" appearing but capture errors
            #to also remove errors from being displayed change to 2>&1 1>/dev/null
            RESULT=$?

            if [ ${RESULT} -eq 0 ]
            then
              echo "${SERVER} decommissioned Successfully"
            else
              echo "${SERVER} decommissioned Failed"
            fi
            done

            blcli_disconnect

            • 3. Re: Basic NSH script for bulk decommissions
              Monoj Padhy

              Just to add on what Bill and Barry mentioned you can avoid "Command execution failed.  Device blah1 not found" by below mentioned steps.

               

              You are getting this error becoz the server is already deregistered from appserver. To avoid getting this error you can have a check server exists, if found then decommission.

               

              for SERVER in $SERVERLIST

              do

              blcli_execute Server serverExists ${SERVER}

              blcli_storeenv $Found

               

              if [[ $Found == "true" ]];then

               

              echo Decommissioning ${SERVER}

                  blcli_execute Server decommissionServer ${SERVER} 1>/dev/null

                   if [ ${RESULT} -eq 0 ]

                    then

                    echo "${SERVER} decommissioned Successfully"

                    else

                    echo "${SERVER} decommissioned Failed"

                   fi

               

              else

               

              echo "Server already deregistered from appserver"

              fi

               

              done

              blcli_disconnect

               

               

              HTH

               

              Blas

              1 of 1 people found this helpful
              • 4. Re: Basic NSH script for bulk decommissions
                Laurelyn Collins

                Aha.  That makes sense, knowing that NSH is going out to the managed servers instead of talking to the console.  Thanks for the clarification.

                • 5. Re: Basic NSH script for bulk decommissions
                  Laurelyn Collins

                  Blas, thank you.  I was intending to eventually try to include a similar routine, but as a novice I get tripped up by syntax all the time so this is very helpful.

                  • 6. Re: Basic NSH script for bulk decommissions
                    Laurelyn Collins

                    Barry, thanks very much.  This looks like exactly what I was hoping for.

                    • 7. Re: Basic NSH script for bulk decommissions
                      Kai Hintze

                      I also found Server decommissionServer in about 30 seconds searching so I'm glad that I'm on the right track. That's pretty good as far as it goes, but when I decommission a server in the GUI it offers to remove dependent components (Inventories, etc) as well. I've been looking for a way to find and delete them as well, but I haven't found that in a couple of hours searching manuals. To make it worse, searching the forum here points out that decommissionServer doesn't remove the license, and one needs an undocumented command to do that.

                       

                      Has anyone got a complete script?

                       

                      Thanks,

                      Kai

                      • 8. Re: Basic NSH script for bulk decommissions
                        Bill Robinson

                        licensing only applies to 8.1 and below.  if you are using 8.2 or later you don't need to worry about unlicensing the agent on the licensing site.

                         

                         

                        when you run the decom from the blcli it should do the cascade removal of the associated 'components' and such.

                        • 9. Re: Basic NSH script for bulk decommissions
                          Kai Hintze

                          Excellent news. Thanks Bill!

                          • 10. Re: Basic NSH script for bulk decommissions
                            Kai Hintze

                            The phrase "should do the cascade removal" made me just nervous enough to check it before I got too enthusiastic. <grin> I confirm that in 8.5.01.231, Search shows components related to the servers before decommission, and does not find them after decommission.