11 Replies Latest reply on May 11, 2011 8:20 AM by Keusch Christian

    Looking for a nsh solution, howto fill in servernames in a "is one of" list

      Hi all

       

      The following script will generate a SmartServerGroup by input a server list.

      The problem here is, any server will generate a new line in the rule-set. To became a

      result, the "match" switch has to be in  "any" position and the rule couldn’t expand with

      other conditions.

      I'm looking now for a way to fill in the server names in a "is one of" list, to have the

      chance to add some conditions with "match all" options.

       

      Does anyone have a idea to solve this?

       

      Thanks & Regards

       

      Christian

       

      __________________________________________________________________________________

      #!/bin/nsh

      #--------------------------------------------------------------------------------------------------

      #

      # Name      : ServerTOSmartgroup.nsh

      # Path      :

      # Written   : Christian Keusch ITConcepts 20.4.2011

      # Tested    :

      #

      # Description: Set List in ServerSmartGroup (carefull: the exist Rul will be replaced)

      #

      # Parameters:   

      #   Sourcefile: ServerList

      #   Target: fully/qualified/name/of/the/smartgroup

      # ----------------------------------------------------------------------------------------------------

      # Modified :

      #

      #

      #

      #-----------------------------------------------------------------------------------------------------

       

       

      #----------------------------------------------------------------------------

      # Declarations

      #----------------------------------------------------------------------------

      DEBUG=0

       

       

      #----------------------------------------------------------------------------

      # print_debug

      #----------------------------------------------------------------------------

      # Set the DEBUG variable to 1 to print out all debug statements

      sub print_debug()

      {

         if test $DEBUG -eq 1

         then

            echo "**DEBUG** ${@}"

         fi

      }

       

      #----------------------------------------------------------------------------

      # bl_connect

      #----------------------------------------------------------------------------

      # Connect to the Appsersver

      sub bl_connect()

      {

        print_debug "connecting...."

        blcli_connect

        if test $? -ne 0

        then

           echo "Cannot contact Appserser.  Please resolve connectivity issues and rerun script."

           exit -1

        else

           print_debug "connected"

        fi

      }

       

      #----------------------------------------------------------------------------

      # main

      #----------------------------------------------------------------------------

       

      SERVER_LIST=${1}

      SMARTGROUP=${2}

       

      bl_connect

       

      if [ ! -s $SERVER_LIST ]; then

          echo "Target Serverlist: ${IST_SERVER_LIST} ...missing or empty" >&2

          exit 1

      fi

       

       

      blcli_execute SmartServerGroup findGroupByQualifiedName "$SMARTGROUP" > /dev/null 2>&1

      blcli_storeenv SMARTGROUP_ID > /dev/null 2>&1

       

      if [ $? != "0" ]; then

          echo "SmartGroup unknown: $SMARTGROUP"  >&2

          exit 1

      fi

       

      FIRSTLINE=1

      blcli_execute SmartServerGroup setMatchAll "$SMARTGROUP" "false" > /dev/null 2>&1

       

      for ZEILE in $(cat ${SERVER_LIST}| sed -e 's/[^ -~]//g')

      do

          if [ $FIRSTLINE = 1 ]; then

               blcli_execute SmartServerGroup resetConditions "$SMARTGROUP" "NAME" "starts with" "$ZEILE" > /dev/null 2>&1

       

               FIRSTLINE=0

               print_debug "Add $ZEILE to first condition"

          else

               blcli_execute SmartServerGroup addCondition "$SMARTGROUP" "NAME" "starts with" "$ZEILE" > /dev/null 2>&1

       

               print_debug "Add $ZEILE to conditions"

          fi

      done

       

      echo "Done"

      exit 0