1 Reply Latest reply on Jul 19, 2016 7:07 PM by Bill Robinson

    How to get nsh job key?

    michael huttner

      To:  Bill Robinson

       

      In one of your NSH script jobs, your code uses job arg $0 to parse the job's scriptpath for a "job key" string, which you then use to query for an nsh job key, eg:

       

      scriptPath=$0

      scriptPath=/bladelogic/nsh/NSH/tmp/lsdie1cke_c/scripts/job__6447c65a-d46e-445e-b7d5-e26e43870564/script_DBKey-SJobKeyImpl-2000182-2__d99f71dc-ff8b-4ebd-940b-2d17effb7e51.2035622.1_IRCmasterComplianceValidate.nsh

       

      your code works like so

       

      nshJobKey=DBKey:SJobKeyImpl:6445573-28

      > blcli_execute Job findByDBKey DBKey:SJobKeyImpl:6445573-28

      JOBKEY=com.bladelogic.om.infra.model.job.script.NSHScriptJobImpl@4b62bc8b

       

      however, when I try this on a different job, it fails:

      nshJobKey= DBKey-SJobKeyImpl-2000182-2

      > blcli_execute Job findByDBKey DBKey-SJobKeyImpl-2000182-2

      Cannot store a failed command result

       

      Can you help explain what you are doing?

        • 1. Re: How to get nsh job key?
          Bill Robinson

          the code was like:

           

           

          getNSHScriptKey()

          {

                  print_debug1 "Entering function: ${0}..."

                  local scriptPath="${1}" && print_debug2 "scriptPath=${scriptPath}"

           

                  local nshJobKey="`echo ${scriptPath} |sed "s/.*_\(DBKey.*\)__.*/\1/g" | sed "s/-/:/1" | sed "s/-/:/1"`"

                  BLCLICMD=(Job findByDBKey ${nshJobKey})

                  runBlcliCmd

          BLCLICMD=(NSHScriptJob getScriptKey)

                  runBlcliCmd nshScriptKey

          }

           

          the 'runBlcliCmd' is a wrapper to run the blcli.  and you seem to have cut out bits of what you are running because :

           

          > blcli_execute Job findByDBKey DBKey-SJobKeyImpl-2000182-2

          does not throw:

          "Cannot store a failed command result"

          blcli_storeenv will throw that error.

           

          so what exactly are you running ?  and you have the job key as soon as you run the echo and sed.  you don't need to use the blcli to get the job key.