5 Replies Latest reply on Jul 29, 2014 11:24 AM by Bill Robinson

    Job that Updates/Changes a Server Property Value

    James Donohue

      Hi,

       

      Is there a way to run some sort of job that will check a Registry value, a Service or a file on a Server and based on what it finds, can you change/update a Server Property. Right now, I have to define my Property Values when I import them or manually change a Property (i.e. IS_IIS=YES) to reflect that. I want to update a Property named IS_IIS to equal YES or NO based on if the Target is an IIS Server or not. 

       

      In Short: Is there a way that I can schedule some sort of job to go out and check something on my Target Servers (i.e. Service existence and/or State) and based on what it finds, to change / update an existing Server Property?   

        • 1. Re: Job that Updates/Changes a Server Property Value
          Bill Robinson

          yes - you can create a nsh script job that gets the value and then uses the blcli to set the value.    depending on how many targets you have, you might want to break it into 2 jobs - one type 1 nsh job to get the data, and a type 2 to aggregate the values across all servers into a format the 'Server bulkSetServerPropertyValues' can use.  you would do this because spinning up a bunch of type 1 nsh jobs w/ blcli in them concurrently can hoze your appserver.

          2 of 2 people found this helpful
          • 2. Re: Job that Updates/Changes a Server Property Value
            Mike Jones

            James,

             

            Below is a simple script we use to update the IS_VIRTUAL property on Windows servers in this case if it is a VMWare server. You could use the same approach for what you want to do just change the query command, the detection and the property.

             

            This is a type 1 script but we limit the number of hosts to process in parallel to ensure it doesn't impact the app server as Bill mentioned above

             

             

            #****************************************************************************

            #Standard error handling

            do_error()

              {

              echo $@

              exit -1

              }

             

             

            #Just to make life easier

            export VMQUERY="echo. | wmic computersystem get manufacturer"

             

             

             

             

            #Next line assumes function returns string to STDOUT on success

            echo Executing "$VMQUERY"

               [[ -z $(nexec -e cmd /c "$VMQUERY" | grep VMware) ]] && {

                  do_error "Not a VMware server"} || {

                  echo Updating server IS_VIRTUAL property

                  blcli_execute Server setPropertyValueByName $NSH_RUNCMD_HOST "IS_VIRTUAL*" true

                 

                }

             

            #******************************************************************************

            2 of 2 people found this helpful
            • 3. Re: Job that Updates/Changes a Server Property Value
              Christopher Dale

              here is script as example i use to check a reg key and set a value....

               

              ###################################################################
              #
              # SetRebootProperty.nsh
              # by Greg Kullberg
              # April 26, 2006
              #
              # REVISION HISTORY
              # Modified May 9, 2006 for compatability with version 7.x
              # Modified May 25, 2006 - using blquery instead of reg to work w/ Windows 2000 systems
              #  also checks to see if it is running against a windows system
              # Modified Dec 14, 2006 (GK) - added better checking for DEBUG
              # Modified Jan 15, 2006 (GK) - now using the NSH_RUNCMD_HOST variable to get target host
              #
              # DESCRIPTION
              # Determines whether or not a Windows server needs to be rebooted
              #
              # This script will execute a 'reg query' and will check the registry
              # for the PendingFileRenameOperations key.  Depending on the result,
              # the script will set the NEEDS_REBOOT server property.
              #
              # Required Properties: NEEDS_REBOOT
              # Script type:  Runscript
              #
              ###################################################################

              # Declare variables
              NEEDS_REBOOT="FALSE"
              DEBUG=$1

              # Set the DEBUG variable to 1 to print out all debug statements
              sub print_debug()
              {
              if [ "$DEBUG" = "TRUE" -o "$DEBUG" = "True" -o "$DEBUG" = "true"]
              then
                echo $@
              fi
              }


              # Get Server's hostname and OS
              HOST=$NSH_RUNCMD_HOST
              OS=`uname -s`
              echo "Host is $HOST, OS is $OS"

               

              # Subroutine takes two arguments: The property name and the value to which
              # the property should be set.  It is assumed that the global server variable
              # defines the server for which the property should be set.
              sub set_server_property()
              {
              PROP_NAME=$1
              PROP_VALUE=$2

              print_debug "Executing command: blcli Server setPropertyValue $SERVER_ID $PROP_NAME $PROP_VALUE"
              RESULT=`blcli Server setPropertyValue $SERVER_ID $PROP_NAME "$PROP_VALUE"`
              if test "$?" = "0"
              then
                print_debug "$PROP_NAME property set to $PROP_VALUE on $HOST."
              else
                echo "ERROR: Failed to set $PROP_NAME property for $HOST: $RESULT"
              fi
              }

              # If the host isn't windows then we don't need to do anything
              if [ "$OS" = "WindowsNT" ]
              then
              # Get the server's ID
              print_debug "Executing command blcli Server getServerDBKeyByName $HOST"
              SERVER_ID=`blcli Server getServerDBKeyByName $HOST`
              print_debug echo "Result is $?"
              print_debug "Server ID is $SERVER_ID"

              # Check the Session Manager Registry for PendingFileRenameOperations Key
              RESULT="`blquery -h $HOST -e 'reg_value_exists ("HKEY_LOCAL_MACHINE\\\\SYSTEM\\\\CurrentControlSet\\\\Control\\\\Session Manager\\\\PendingFileRenameOperations")' | tr -d '[:cntrl:]'`"

              if [ "$RESULT" = "1" ]
              then
                echo "Server needs to be rebooted."
                print_debug "Result from registry is: $RESULT"
                NEEDS_REBOOT="TRUE"
              else
                echo "Server does not need to be rebooted."
                NEEDS_REBOOT="FALSE"
              fi


              # Set the NEEDS_REBOOT property
              echo "Setting NEEDS_REBOOT to $NEEDS_REBOOT"
              set_server_property "NEEDS_REBOOT" "$NEEDS_REBOOT"
              else
              echo "$HOST is not Windows, skipping"
              fi

               


              • 4. Re: Job that Updates/Changes a Server Property Value
                James Donohue

                Thank you All; very helpful. Now to learn NSH. . . .

                • 5. Re: Job that Updates/Changes a Server Property Value
                  Bill Robinson

                  Nsh is based on zsh 4.3.4.  which is fairly similar to bash, though zsh adds a lot on top of bash.