4 Replies Latest reply on Jan 31, 2013 4:57 AM by Jesper Rellme

    NSH script to add Server with Server properties


      I'm looking for some NSH script experience to solve the following use-case. How is the baest way to loop through the undetermind number of server properties and their values? I guess this is fairly easy and I'm looking for some directions.


      NSH script RegisterServer.nsh












      blcli Server addServer $SERVER_NAME

      SERVER_GROUP_ID = blcli ServerGroup groupNameToId $SERVER_GROUP

      blcli StaticServerGroup addServerToServerGroupByName $SERVER_GROUP_ID $SERVER_NAME


      foreach SERVER_PROPERTY

           Server setPropertyValueByName  $SERVER_NAME $SERVER_PROPERTYn $VALUEn


        • 1. Re: NSH script to add Server with Server properties

          I found an old NSH script which did everything I asked for, just need to update it to work with later BSA version. Below you can find a snipet of the scripts that loops through n PROPERTY_VALUES and assign them to a server.


          sub print_usage()


              echo "\n\n\n"

              echo "Usage: $PROGRAM -h <hostlist> [-r <Profiles> ] [-p <Properties> | ]\n"

              echo "  -h <hostlist>    - Space-delimited list of hosts to add to RBAC"

              echo "  -r <Profiles>    - Space-delimited list of Resource Profiles the host should be in."

              echo "  -p <Properties>  - Space-delimited list of properties to set for the host"

              echo "       ex: <Prop1>=<Val1> <Prop2>=<Val2>"

              echo "\n\n\n"

              exit 1



          sub set_properties()


              # Set any properties passed into the script as arguments

              if ! test -z "$SERVER_PROPS"


                  SERVER_PROPS_TMP=`echo $SERVER_PROPS | sed -e 's/:/\ /g'`

                  foreach proppair in $SERVER_PROPS_TMP


                      PROP_NAME=`echo $proppair | fields -d "=" 1`

                      PROP_VALUE=`echo $proppair | fields -d "=" 2`

                      print_debug "Property name: $PROP_NAME"

                      print_debug "Property value: $PROP_VALUE"

                      #check_property_existence "$PROP_NAME"

                      set_server_property "$PROP_NAME" "$PROP_VALUE"



              print_debug "Finished setting argument properties for $server."




          1 of 1 people found this helpful
          • 2. Re: NSH script to add Server with Server properties
            Bill Robinson

            why not use the 'bulkSetServerProperties' or the bulkImportServers commands (something like that) ?

            • 3. Re: NSH script to add Server with Server properties

              I know that is one way you can do this but it requires the calling program to create the CSV file which I would like to avoid.


              I have completed the script and what I'm struggeling with now is how to wrap it into a BL Script and create a script job.


              from a NSH shell I can run the script with

              >nsh RegisterServerPerformance.nsh -h serverName -g /ServerGroup1 /ServerGroup2 -p Property1=value1 Property2=value2


              This works very well and the new server is added to BSA, assigned to all server groups and get property values set.


              When I add this to BSA as a script I select second option

              ScreenHunter_242 Jan. 31 10.58.jpg

              For the parameters section I have added my three input parameters

              -h HOST

              -g GROUPS

              -p PROPERTIES=VALUE

              but I'm also forced to add either %h or %f because its a type2


              when I run this script as a job in BSA I don't want to taget a specific server since the purpose of the script is to add a new server.

              ScreenHunter_243 Jan. 31 11.03.jpg

              How can I do this? My script job fails if I run it with no targets.

              • 4. Re: NSH script to add Server with Server properties

                I had a check in my script to check if there was a target server provided. Removing that check solved the problem.


                I have uploaded the script here: