10 Replies Latest reply on Dec 21, 2017 7:24 AM by Tim Musson

    scripted blcli_execute patch catalog smartgroup creation with grouping & AND/OR

    Tim Musson

      I have a script/job that modifies (clear, add new condition, add new condition) a Patch Catalog SmartGroup (we use it to make sure Production gets the same set of patches as Development).

      Currently it looks like this:

      Any HotFix Where ?DATE_CREATED? after 2017-12-14 18:00:00 OR

      Any Windows Bulletin Where ?DATE_CREATED? after 2017-12-14 18:00:00

       

      Now we need to get more complex.

      (Any HotFix Where ?DATE_CREATED? after 2017-12-11 00:05:00 AND

      Any HotFix Where ?DATE_CREATED? before 2017-12-15 23:55:00) OR

      (Any Windows Bulletin Where ?DATE_CREATED? after 2017-12-11 00:05:00 AND

      Any Windows Bulletin Where ?DATE_CREATED? after 2017-12-15 23:55:00)

       

      I'm not finding how to inject the parentheses and set the AND/OR...

       

      Any suggestions?

       

      Here is my current script that is working just fine:

      # Clears then sets the new Conditions (Date) of a Patch Catalog Smart Group

      set -e

       

      processPatchCatalogSmartGroup() {

         blcli_execute Group getGroupByQualifiedName 5017 "$PatchingSmartGroup"; echo " (Get the SG object)"

         blcli_execute Utility storeTargetObject groupObject; echo " (Store the SG object)"

         blcli_execute Condition createPropertyCondition "$propertyClassName" "$propertyName" "$operator" "$propertyValue"; echo " (Define the new SG Conditions - $propertyValue)"

         blcli_execute Utility storeTargetObject conditionObject; echo " (Store the new SG Conditions)"

         blcli_execute SmartGroup $1 NAMED_OBJECT=groupObject NAMED_OBJECT=conditionObject; echo " (Update the SG with the new Conditions and '$1')"

         blcli_execute SmartGroup save NAMED_OBJECT=groupObject; echo " (Save the SG)"

      }

       

      # Variables

         WindowsPatchCatalogSmartGroupLocation=$2

         WindowsPatchCatalogSmartGroup=$3

         PatchingSmartGroup="$WindowsPatchCatalogSmartGroupLocation/$WindowsPatchCatalogSmartGroup"

         propertyClassName1="Class://SystemObject/Depot Object/Software/Win Depot Software/HotFix" #"

         propertyClassName2="Class://SystemObject/Depot Object/Software/Windows Bulletin" #"

         propertyName="DATE_CREATED"

         operator="after"

           zmodload zsh/datetime

         YYYYMMDD="$(strftime '%Y-%m-%d' $((${EPOCHSECONDS}+86400*2)))" # Two days in the future (this runs Tuesday, so value for Dec'17 is 2017-12-14)

         propertyValue="$YYYYMMDD 18:00:00"

      # End Variables

       

         echo "~~~~~~~~~~~~~~~~~"

         echo "Updating the Windows Patch Catalog Smart Group: $WindowsPatchCatalogSmartGroupLocation/$WindowsPatchCatalogSmartGroup

          With:  $propertyClassName1 - $propertyName - $operator - $propertyValue

          And:   $propertyClassName2 - $propertyName - $operator - $propertyValue"

       

      # Call to do the work

         echo "~~~~~~~~~~~~~~~~~ This bit is resetting & saving the first condition (ie. clears all others!)"

         propertyClassName="$propertyClassName1"

         processPatchCatalogSmartGroup resetConditions

         echo "~~~~~~~~~~~~~~~~~ This bit _adds_ the second condition"

         propertyClassName="$propertyClassName2"

         processPatchCatalogSmartGroup addCondition

         echo "~~~~~~~~~~~~~~~~~"

      # End Call to do the work