8 Replies Latest reply on Jun 16, 2005 3:32 AM by Greg Kullberg

    Trouble getting result of blcli call in NSH script

      I'm currently using the update-server-agent-status.nsh script, and want to use it to set the AGENT_STATUS server property against all my servers. The idea is that if a server is up, the property gets set and picked up by a smart server group of all online servers (and vice versa).

       

      The section of my script that I'm using is this:


      for server in $SERVERS_LIST
      do
      echo "Updating $server"

      print_verbose "Running blcli Utility updateServersStatus $server $THREAD_POOL_SIZE $TIMEOUT $UPDATE_ALL_PROPERTIES"
      RESULT=`blcli Utility updateServersStatus $server $THREAD_POOL_SIZE $TIMEOUT $UPDATE_ALL_PROPERTIES`
      UPDATE_EXIT_CODE=$?
      print_verbose "code = $UPDATE_EXIT_CODE"
      print_verbose "result = $RESULT"

      if [ "x$RESULT" = "xvoid" ]
      then
      print_verbose "Updated $server"
      else
      echo "Error Updating Server: $server"
      echo "Error Code: $UPDATE_EXIT_CODE Output: $RESULT"
      fi

      done

       

      However, the output from my script is as follows:

       

      Info 06/14/2005 17:45:31 Updating vmsun44

      Info 06/14/2005 17:45:31 2005-06-14-17-45-31 Running blcli Utility updateServersStatus vmsun44 20 60000 true

      Info 06/14/2005 17:45:52 2005-06-14-17-45-52 code = 0

      Info 06/14/2005 17:45:52 2005-06-14-17-45-52 result = void

      Info 06/14/2005 17:45:52 2005-06-14-17-45-52 Updated vmsun44

      Info 06/14/2005 17:45:52 Updating vmdom101

      Info 06/14/2005 17:45:52 2005-06-14-17-45-52 Running blcli Utility updateServersStatus vmdom101 20 60000 true

      Error 06/14/2005 17:46:04 Exception while retrieving host status (overview) from app server : vmdom101 : com.bladelogic.mfw.util.BlAppServerException: Connection refused: vmdom101

      Info 06/14/2005 17:46:05 2005-06-14-17-46-05 code = 0

      Info 06/14/2005 17:46:05 2005-06-14-17-46-05 result = void

      Info 06/14/2005 17:46:05 2005-06-14-17-46-05 Updated vmdom101

       

      Note that the first server works fine, but not the second. They both produce the same output for CODE and RESULT. I can't seem to capture the exception and check the RESULT variable, since it is the same for an online server and a server that is down. Any ideas?

        • 1. Re: Trouble getting result of blcli call in NSH script

          Due to a bug in NSH, any script like the following:

           

          VAR=`execute command`

          echo $?

           

          Will always return 0 for $?.

          $? is supposed to be set with the actual return code from "execute command" but it's not.

           

          This bug has been fixed in the upcoming 6.3.1 release.

           

          I don't know if this fix will help your situation but relying on $? after calling a command like VAR=`asd`

          is not a reliable mechanism (until 6.3.1).

          • 2. Re: Trouble getting result of blcli call in NSH script

            Three things:

             

            1. Redirect stderr to stdout to capture all output of blcli using the 2>&1 redirection:

             

            RESULT=`blcli Utility updateServersStatus $server $THREAD_POOL_SIZE $TIMEOUT $UPDATE_ALL_PROPERTIES 2>&1`

             

            2. As Sean mentioned X=`command` returns error code 0 and not the error code of command. You can use a compound command using ; to append the error code to the output:

             

            RESULT=`blcli Utility updateServersStatus $server $THREAD_POOL_SIZE $TIMEOUT $UPDATE_ALL_PROPERTIES 2>&1 ; echo error code is $? `

             

            3. Finally, you should put the assignment in double quotes in case the output has new lines:

             

            RESULT="`blcli Utility updateServersStatus $server $THREAD_POOL_SIZE $TIMEOUT $UPDATE_ALL_PROPERTIES 2>&1 ; echo error code is $? `"

            • 3. Re: Trouble getting result of blcli call in NSH script

              Thanks Andrew, that worked. I added a call to update the IS_ONLINE parameter, and now I have a smart server groups for all Online and Offline servers. Here's the final code:


              SERVERS_LIST="`echo $SERVERS_LIST | sed -e 's/:/ /g'`"
              ONLINE_KEY="`blcli Property propertyNameToDBKey IS_ONLINE`"
              print_verbose "IS_ONLINE DBKey is $ONLINE_KEY."

              for server in $SERVERS_LIST
              do
              echo "Updating $server"
              SERVER_ID="`blcli Server getServerIdByName $server`"
              print_verbose "Server ID is $SERVER_ID."

              print_verbose "Running blcli Utility updateServersStatus $server $THREAD_POOL_SIZE $TIMEOUT $UPDATE_ALL_PROPERTIES"
              RESULT="`blcli Utility updateServersStatus $server $THREAD_POOL_SIZE $TIMEOUT $UPDATE_ALL_PROPERTIES 2>&1`"
              UPDATE_EXIT_CODE=$?

              if [ "x$RESULT" = "xvoid" ]
              then
              print_verbose "Updated $server."
              print_verbose "Running blcli Server addPropertyValue $SERVER_ID $ONLINE_KEY TRUE"
              RESULT="`blcli Server addPropertyValue $SERVER_ID $ONLINE_KEY TRUE`"
              else
              echo "Error Updating Server: $server"
              echo "Error Code: $UPDATE_EXIT_CODE Output: $RESULT."
              print_verbose "Running blcli Server addPropertyValue $SERVER_ID $ONLINE_KEY FALSE"
              RESULT="`blcli Server addPropertyValue $SERVER_ID $ONLINE_KEY FALSE`"
              fi

              print_verbose "Result of updating IS_ONLINE property is $RESULT."
              done

               

              • 4. Re: Trouble getting result of blcli call in NSH script

                "blcli Utility updateServersStatus" should already update AGENT_STATUS to "agent is online" or "agent is not responding" so you can create a smart group off of that. If it is not setting that value, increase the timeout value for updateServersStatus.

                • 5. Re: Trouble getting result of blcli call in NSH script

                  That's what I thought too. Check out my log data from the orignal post. The problem was in the updateServerStatus command to begin with:

                   

                  Info 06/14/2005 17:45:52 2005-06-14-17-45-52 Running blcli Utility updateServersStatus vmdom101 20 60000 true

                  Error 06/14/2005 17:46:04 Exception while retrieving host status (overview) from app server : vmdom101 : com.bladelogic.mfw.util.BlAppServerException: Connection refused: vmdom101

                   

                  Even if I ran 'blcli Utility updateServersStatus vmdom101 20 60000 true' from NSH, it wouldn't update the server status; it would only return this error message.

                  • 6. Re: Trouble getting result of blcli call in NSH script

                    Try this:

                    "blcli Utility updateServersStatus vmdom101 20 60000 false"

                     

                    I think that it is a bug that AGENT_STATUS is not updated when Update All Properties == true

                    • 7. Re: Trouble getting result of blcli call in NSH script

                      This bug has been fixed in an upcoming release of BladeLogic (currently slated for 6.3.2).

                      • 8. Re: Trouble getting result of blcli call in NSH script

                        That does work, but of course it's only good when you care about the license status. They also want to make sure their servers IP addresses are up to date too.