Server Automation (SA): How to insert bourne string variables into OGFS filter expressions.

  • KM03260967
  • 30-Sep-2018
  • 04-Jun-2021

Summary

In this article we will provide examples of how to embed bourne string variables into OGFS CLI filter expressions used by Server Automation.

Question

The OGSH environment provides a powerful filesystem based interface that can be interacted with via a command shell (bash) environment.  A versatile feature of most command shells is the ability to perform string variable replcaements against commands.  Some of the OGSH CLI interfaces make use of internal string quoting, which can sometimes make it difficult to figure out how to properly embed a shell string replacement variable.  In this article/KM we will provide examples of how to embed bourne string variables into OGFS CLI filter expressions.
 

Answer

In a com.opsware.search.Filter expression, if a string literal has no spaces, then it can be specified with no quoting.  But if the string contains spacing, then double quotes are required in order to properly specify the string.  Below are two examples of two quoting strategies to embed a shell variable whose value contains a space into a search filter expression:
 
----
[user1@sa1051 method](96) $ v="VMWARE, INC."
 
[user1@sa1051 method](101) $ ./findServerRefs filter="{ServerVO.manufacturer = "'"'"$v"'"'"}"
sa1051.nccs.opsware.com
rhel652-1051.nccs.opsware.com
sa1051b.nccs.opsware.com
rhel72-convergys.nccs.opsware.com
win2k8r2-1051.nccs.opsware.com
win2k12-1051.nccs.opsware.com
 
[user1@sa1051 method](102) $ ./findServerRefs filter='{ServerVO.manufacturer = "'"$v"'"}'
sa1051.nccs.opsware.com
rhel652-1051.nccs.opsware.com
sa1051b.nccs.opsware.com
rhel72-convergys.nccs.opsware.com
win2k8r2-1051.nccs.opsware.com
win2k12-1051.nccs.opsware.com
----