How to run shell scripts and get the results via analysis

Hi Team,

Can you please help me how to get the results in analysis for below shell commands or all multiple endpoints outputs in single file.

powermt display
multipath -ll|grep -i failed"
“lsof |grep “/nfs/SAP”|wc -l”

One way might be to create something like myvalues.csv on each endpoint with key:value as content.
Withing Bigfix create a analyse with, in your example, 3 properties with relevance like:
following text of first “:” of lines whose (it starts with “”) of file “myvalues.csv”

In addition, some checks like “if exists file then … else false” etc. might be usefule.

you can use bigfix API via python or else. Run any cmd and dump the output of the cmd in log and read that log in same work flow.

cmd_argu="/sbin/pvs|grep -v Free >  /tmp/bftask_run_cmd.log"
...
def build_xml(computer_target):

  action_script="""\ndelete __appendfile\
\ndelete /tmp/run_cmd.sh\
\ndelete /tmp/bftask_run_cmd.log\
\nappendfile """+cmd_argu+"""\
\nappendfile chmod 644 /tmp/bftask_run_cmd.log\
\nmove __appendfile /tmp/run_cmd.sh\
\nwait chmod 755 /tmp/run_cmd.sh\
\nwait /bin/sh /tmp/run_cmd.sh\
\ndelete /tmp/run_cmd.sh """

  #print(action_script)
  #exists (operating system) whose (it as string as lowercase contains "Linux" as lowercase)
  xml_query='<?xml version="1.0" encoding="utf-8"?>\
    <BES xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SkipUI="true">\
    <SingleAction>\
        <Title>Deploy: Execute OS Command</Title>\
          <Relevance>exists (operating system) whose (it as string contains regex "Linux|AIX|SunOS|HP-UX" )</Relevance> \
        <ActionScript>\
         '+action_script+'\
        </ActionScript>\
        <SuccessCriteria />\
        <Settings />\
        <SettingsLocks />\
        <Target>'

  xml_query=xml_query+""+computer_target+""+"</Target> </SingleAction></BES>"
  xml=xml_query
  print("\nBuilding Query XML :"+ xml+"\n")
  #sys.exit()
  req_bes_query_id=requests.post(bigfix_URL_action,verify=False,auth=(bigfix_username,bigfix_pwd),data=xml)
  return req_bes_query_id

..
  query='lines of file "/tmp/bftask_run_cmd.log"'
   xml_query='<BESAPI xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BESAPI.xsd"> \
          <ClientQuery>\
                <ApplicabilityRelevance>true</ApplicabilityRelevance>\
                <QueryText>'+query+'</QueryText>\
                <Target>\
                 '+computer_target+'\
                </Target>\
          </ClientQuery>\
          </BESAPI>'
          #print ("\nReading Query Log :" +xml_query)

          req_bes_query_id=requests.post(self.bigfix_URL_client_query,verify=False,auth=(bigfix_username,bigfix_pwd),data=xml_query)
          #print("\nExecuting XML Query for LOG :"+req_bes_query_id.text)
          query_ID=""
          tree2 = ET.fromstring(req_bes_query_id.text)
          for fixlet in tree2.findall('.//ClientQuery'):
                 query_ID=fixlet.find("ID").text

Hi Matthias

Can you help on below and provide me the analysis or property relevance,

powermt display
multipath -ll|grep -i failed"
“lsof |grep “/nfs/SAP”|wc -l”

Hi,
it is not possible to gather this content directly. You need to create a fixlet creating the output. Action script should be similar to:
wait sh -c “lsof |grep “/nfs/SAP”|wc -l >> /tmp/mycontent.txt”

To have a simple test:
echo “testcontent” >> /tmp/mycontent.txt
check with qna:
/opt/BESClient/bin/qna

Q: lines of file "/tmp/mycontent.txt"
A: testcontent
T: 7147

Within the analysis you can import the data using
lines of file “/tmp/mycontent.txt”

Of course, this is not perfect as checks like “exists file” etc. are missing. I would suggest to play a little bit around and have a look at existing analyses and properties.

Good examples can be found in site “BES Inventory and license”, eg. fixlet “hardwareprobe linux” and analyse “hardware information linux”

Thank for your valuable support Matthias