11 Replies Latest reply on Feb 18, 2011 8:59 AM by Amir Khamis

    blquery on software  packages example

      i saw that the new reports engine (BSARA) finally allows queries on an abstract "software package" that maps to windows applications on windows, rpm packages on linux and so on.

      i was wondering if such a query is possible with blquery also.

      ideally i would like some code that print the list of installed software on a given server, that can be used in a type 1 nsh script.

        • 1. Re: blquery on software  packages example

          playing on the same subject i've found something viable

           

          blquery $SERVER -e 'package_record_count("printf(\"%s,%s,%s,%s\n\", NAME, VERSION, VENDOR, show_date(DATE, \"%d %m %Y\"))");'

           

          now my question is about double quotes inside a printf

          how can i insert them?

          right now the example gives something like

           

          BMC BladeLogic RSCD Agent,7.6.0.132,BladeLogic, Inc.,27 07 2009

           

          where i need the fields in double quotes to generate a proper csv file like

           

          "BMC BladeLogic RSCD Agent","7.6.0.132","BladeLogic, Inc.","27 07 2009"

           

          i tried escaping the quotes in various C-like tricks with no results

          • 2. Re: blquery on software  packages example
            Wenchi Liao

            now my question is about double quotes inside a

            printf

            how can i insert them?

            right now the example gives something like

             

            The backslashes need to be doubled up:

             

            blquery $server -e 'package_record_count("printf(\"
            \"%s
            \"\n\",NAME)")'

             

            You can remove one level of quoting if the expression is written in file or a here-doc is used:

             

            blquery localhost -E - <<END

            package_record_count('printf("\"%s\"\n",NAME)')

            END

             

            This line is left blank...

             

            Message was edited by:

            Wenchi Liao

            • 3. Re: blquery on software  packages example

              indeed quoting is something halfway between art and black magic

               

              can i check your magician ability on something more?

              expanding a nsh variable into a printf format string:

              something like

               

              $SERVER=$NSH_RUNCMD_HOST

              package_record_count('printf("$SERVER %s\n",NAME)')

               

              that should output

              server1 package1

              server1 package2

              server1 package3

               

              thank you

              • 4. Re: blquery on software  packages example
                Wenchi Liao

                What is the final output you want to get? I can think of one way of doing this, but it is really ugly and error-prone.

                 

                I would do something like this:

                 

                blquery $SERVER -e .... | while read output

                do

                 

                1. filter out the last number

                echo "$SERVER $output"

                done

                 

                and be done with it. If this runs on Windows, you may need to strip out the newlines.

                • 5. Re: blquery on software  packages example

                  i'm trying to generate a csv report of installed software like:

                  "server1","package1"

                  "server1","package2"

                  "server2","package1"

                  "server2","package2"

                   

                  and i was working towards processing the output of the blquery with awk to prepend the servername onto the output lines but stumbled upon here document and pipe that seem to clash together

                  • 6. Re: blquery on software  packages example
                    Wenchi Liao

                    If you use the here doc, make sure you have the pipe on the right line:

                     

                    blquery $server -E - <<END | while read output; do echo "$server,$output";done

                    package_record_count(...)

                    END

                     

                    or

                     

                    blquery $server -E - <<END | awk -v host=$server ...

                    package_record_count(...)

                    END

                    • 7. Re: blquery on software  packages example

                      thank you for filling this thread of very useful info

                      • 8. Re: blquery on software  packages example

                        by reference i've completed my asset job

                        it takes 50 minutes to process 1800 servers

                        not bad, instead of a lengthy snapshot + etl + query cycle by bsara :)

                        • 9. Re: blquery on software  packages example
                          Amir Khamis

                          Hello,

                          I need some help with this command please:

                          blquery -h SERVERNAME -e 'package_record_count("printf(\"%s,%s,%s,%s\n\", NAME, VERSION, VENDOR, show_date(DATE, \"%d %m %Y\"))");'|grep -i open

                           

                          this works perfect and prints an output like this:

                          penssh-askpass,4.3p2-36.el5_4.2,Red Hat, Inc.,02 12 2009

                          openssh-server,4.3p2-41.el5,Red Hat, Inc.,30 06 2010

                          openmotif,2.3.1-2.el5,Red Hat, Inc.,14 01 2010

                          penssh-askpass,4.3p2-36.el5_4.2,Red Hat, Inc.,02 12 2009

                          openssh-server,4.3p2-41.el5,Red Hat, Inc.,30 06 2010

                          openmotif,2.3.1-2.el5,Red Hat, Inc.,14 01 2010

                          penssh-askpass,4.3p2-36.el5_4.2,Red Hat, Inc.,02 12 2009
                          openssh-server,4.3p2-41.el5,Red Hat, Inc.,30 06 2010
                          openmotif,2.3.1-2.el5,Red Hat, Inc.,14 01 2010

                           

                           

                          I just need the actual servername to print before the package I am executing against

                          SERVERNAME,penssh-askpass,4.3p2-36.el5_4.2,Red Hat, Inc.,02 12 2009
                          SERVERNAME,openssh-server,4.3p2-41.el5,Red Hat, Inc.,30 06 2010
                          SERVERNAME,openmotif,2.3.1-2.el5,Red Hat, Inc.,14 01 2010

                           

                          where SERVERNAME is the actual servername.

                           

                          can you please help?

                           

                          thanks

                          • 10. Re: blquery on software  packages example

                            Try this,

                             

                            blquery -h $SERVERNAME -e 'package_record_count("printf(\"%s,%s,%s,%s\n\", NAME, VERSION, VENDOR, show_date(DATE, \"%d %m %Y\"))");'|grep -i open|while read output;do echo $SERVERNAME,$output;done

                            • 11. Re: blquery on software  packages example
                              Amir Khamis

                              Thank you so much Barry, your example worked and I just got another example I like to share since this may be handy which I just recieved from Bill Robinson:

                              printf(\"%s,%s,%s,%s,%s\n\" , $HOSTNAME, NAME, VERSION, VENDOR, show_date(DATE, \"%d %m %Y\"))");'

                               

                              thanks again for your help Barry and Bill