7 Replies Latest reply on Aug 1, 2006 8:01 PM by Craig Williams

    blquery within NSH

      I would like to invoke the following command from within a NSH script:

      blquery servername -e 'service_exists ("$SVC")'


      I'll be d*mned if I can invoke this without some kind of error:

      unknown file attribute

      unknown operand "$SVC"

      no matches found: (MSSQLServer)'

      unknown operand "MSSQLServer"

      The double and single quotes are killing me.


      I've tried escaping it a dozen different ways...

        • 1. Re: blquery within NSH

          Yeah, it's only been a day, but maybe I didn't explain so well.

          Here's another example. Why doesn't the 3rd invocation produce the same results as the first? I need to invoke the 3rd way in my real script because it's nested inside of 2 loops.


          The script

          echo No vars
          blquery CHIASP75.ent.ad.ntrs.com -e 'service_exists ("MSSQLSERVER")'

          echo Host var
          blquery $HOST -e 'service_exists ("MSSQLSERVER")'

          echo Svc var
          blquery CHIASP75.ent.ad.ntrs.com -e 'service_exists ("$SVC")'


          The log

          Started running the job 'please_kill_me'
          No vars
          Host var
          Svc var
          Exit Code 0
          The job 'please_kill_me' has succeeded


          • 2. Re: blquery within NSH

            As your $SVC is between cote, it isn't substitute. You should write something like :


            QUERY='service_exists ('$SVC')'

            blquery CHIASP75.ent.ad.ntrs.com -e $QUERY

            • 3. Re: blquery within NSH

              The usage of blquery is very specific. The service name must be within double quotes, and the expression must be within single quotes.

              I've tried many variations, but any deviation from that fails.

              My full script has this statement nested with a couple for loops (for $SERVER, for $SVC) so I need to use a service variable. Tried your suggestion, but it still uses quotes which prevent expansion.

              • 4. Re: blquery within NSH

                Hi Craig,


                Try :





                blquery whatevermyserveris.com -e 'service_exists ("'$

                '")' #thats double quotes single quotes $
                single quotes double quotes


                Gives a return code of 1 if service exists

                • 5. Re: blquery within NSH

                  Tried that out Stephen, but still no joy

                  Attached the sample script and log w/ your suggestion

                  • 6. Re: blquery within NSH
                    Olivier KARREMAN

                    Hi Craig,


                    I've tried this on my laptop and to me it seems OK :


                    HOST=<your host>

                    SERVICE=<your service>

                    1. Here we are going to concatenate two strings with a variable in between:

                    COMMAND="blquery $HOST -e 'service_exists (\""$SERVICE"\")'"

                    nsh -c "$COMMAND"


                    Cheers, Olivier.

                    • 7. Re: blquery within NSH

                      So sorry Stephen, your suggestion does work!

                      I was just spelled the service name wrong when I tested your code (doh)!

                      Could you explain how that combination of single/double quotes and braces allows the variable to expand?