5 Replies Latest reply on Mar 28, 2013 7:49 AM by Lukas Vu

    Using variables in blquery

      Hello,

       

      I've been trying to create a script to detect Java version on Windows server. The thing is, it doesn't work when I assign the key or value to variable. If I pass it static directly inside the command, it works like a charm.

       

      TSERVER_NAME=${NSH_RUNCMD_HOST}
      TJAVA2="Java Development Kit"
      
      TJAVA_VERSION=`blquery -h ${SERVER_NAME} -e 'reg_key_exists("HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\JavaSoft\\\\'${TJAVA2}'")' | tr -d '[:cntrl:]'`
      

       

      I have tried many version from all what I have read, combibing single/double quotes etc. Nothing seemed to work. Also, it sounds to me that TJAVA2 gets parsed without spaces, so the script checks for HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\JavaSoft\\\\JavaDevelopmentKit

       

      Any idea about how to make this work, please. I've been searching for few days already with no luck.

       

      Thank you.

      Lukas

        • 1. Re: Using variables in blquery
          Siddu angadi

          Hi Lukas,

           

          Edit your script as below:

           

          TSERVER_NAME=$1  ## if you are passing ${NSH_RUNCMD_HOST} as 1st parameter in NSHScripting.

           

           

          Thanks

          Siddu

          • 2. Re: Using variables in blquery

            Hello,

             

            Thanks for quick answer and recommendation. Although, I'm not sure if that's the thing. Because when I pass:

             

            TJAVA_VERSION=`blquery -h ${SERVER_NAME} -e 'reg_key_exists("HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\JavaSoft\\\\Java Development Kit")' | tr -d '[:cntrl:]'`

            It works just fine. The problem is passing variable (as registry key) instead of registry key directly.

            • 3. Re: Using variables in blquery
              Dipak Gaigole

              Try using double quotes.

              Here is a simple use case showing failure as well as sucess:

               

              vl-pun-blg-dv08# FILE="/tmp/this is my test file"

              vl-pun-blg-dv08# blquery -h localhost -e 'sprintf ("%s", "'${FILE}'" )'

              /tmp/thisismytestfile

              vl-pun-blg-dv08# blquery -h localhost -e "sprintf (\"%s\", \"'${FILE}'\" )"

              '/tmp/this is my test file'

              vl-pun-blg-dv08# blquery -h localhost -e "sprintf (\"%s\", \"${FILE}\" )"

              /tmp/this is my test file

              vl-pun-blg-dv08# blquery -h localhost -e " (\"%s\", \"${FILE}\" )"

              vl-pun-blg-dv08# ls -l "$FILE"

              -rw-r--r--   1 root     root            0 Mar 19 14:37 /tmp/this is my test file

              vl-pun-blg-dv08# blquery -h localhost -e "file_exists ( \"${FILE}\" )"

              1

              vl-pun-blg-dv08#

               

               

              So bellow should work:
              TJAVA_VERSION=`blquery -h ${SERVER_NAME} -e "reg_key_exists(\"HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\JavaSoft\\\\${TJAVA2}\")" | tr -d '[:cntrl:]'`

              • 4. Re: Using variables in blquery

                Hello,

                 

                this seems to be working, let me try it on my script.

                 

                I will get back here tomorrow with results.

                 

                Thank you very much!

                Lukas

                • 5. Re: Using variables in blquery

                  Hi again,

                   

                  so my results are that it won't work the way of

                   

                  TJAVA_VERSION=`blquery -h ${SERVER_NAME} -e "reg_key_exists(\"HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\JavaSoft\\\\${TJAVA2}\")" | tr -d '[:cntrl:]'`

                   

                  But, when storing all key in a variable, it seems to work:

                  CHECK="HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\JavaSoft\\\\${TJAVA2}"

                  TJAVA_VERSION=`blquery -h ${SERVER_NAME} -e "reg_key_exists(\"${CHECK}\")" | tr -d '[:cntrl:]'`

                   

                  One more question, do you know when there's an error in script to ignore it and continue executing next? I believe now it stops and says error.

                   

                  Thank you!

                  Lukas