12 Replies Latest reply on Nov 20, 2017 6:12 AM by Bill Robinson

    [SCRIPT] - NSH from APPserver to Bladelogic

    Yann Michalak

      Hi guys,

       

      we have a strange behavior when we try to deploy "JOB or BatchJob" from APPserver.

       

       

      Here the code used :

       

      deploy BatchJOB.nsh :

       

      SERVICE_PROFILE_NAME=$1

      USERNAME_USER=UserName

      AUTH_TYPE=SRP

      PASSWORD_USER=MyPassword

      APP_SERVER_HOST=VIP-LB

      ROLE_NAME=MyRole

       

      SERVER_NAME=$2

       

      # JOB_GROUP = Job Group containing job to execute

      #JOB_GROUP="/Application Deployments"

      JOB_GROUP=$3

      #JOB_GROUP=`echo $JOB_GROUP | sed -e "s/%20/ /g"`

       

      # JOB_NAME = Name of Job to execute

      #JOB_NAME="IIS"

      JOB_NAME=$4

      #JOB_NAME=`echo $JOB_NAME | sed -e "s/%20/ /g"`

       

      # set up connection

      blcred cred -acquire -profile "$SERVICE_PROFILE_NAME" -username "$USERNAME_USER" -password "$PASSWORD_USER"

      blcli_setoption serviceProfileName $SERVICE_PROFILE_NAME

      blcli_setoption authType $AUTH_TYPE

      blcli_setoption userName $USERNAME_USER

      blcli_setoption password $PASSWORD_USER

      blcli_setoption appserverHost $APP_SERVER_HOST

      blcli_setoption roleName $ROLE_NAME

      blcli_connect

       

       

      blcli_execute BatchJob getDBKeyByGroupAndName "$JOB_GROUP" "$JOB_NAME"

      blcli_storeenv JOB_KEY

       

      #Clear old target servers from batch job

      blcli_execute Job clearTargetServers $JOB_KEY

      blcli_storeenv JOB_KEY

       

      blcli_execute BatchJob addNamedServerToJobByJobDBKey "$JOB_KEY" "$SERVER_NAME"

      blcli_storeenv JOB_KEY

       

      blcli_execute BatchJob executeJobAndWait $JOB_KEY

      blcli_destroy

       

       

      DeployJob.nsh

       

      SERVICE_PROFILE_NAME=$1

      USERNAME_USER=UserName

      AUTH_TYPE=SRP

      PASSWORD_USER=MyPassword

      APP_SERVER_HOST=VIP-LB

      ROLE_NAME=MyRole

       

      # set up connection

      blcred cred -acquire -profile "$SERVICE_PROFILE_NAME" -username "$USERNAME_USER" -password "$PASSWORD_USER"

      blcli_setoption serviceProfileName $SERVICE_PROFILE_NAME

      blcli_setoption authType $AUTH_TYPE

      blcli_setoption userName $USERNAME_USER

      blcli_setoption password $PASSWORD_USER

      blcli_setoption appserverHost $APP_SERVER_HOST

      blcli_setoption roleName $ROLE_NAME

      blcli_connect

       

      JOB_KEY=$2

      SERVER_NAME=$3

      JOBTYPE=$4

       

      #Clear old target servers from batch job

      blcli_execute Job clearTargetServers $JOB_KEY

      blcli_storeenv JOB_KEY

       

      if [[  ${JOBTYPE} == "BatchJob" ]];then

          blcli_execute BatchJob addNamedServerToJobByJobDBKey "$JOB_KEY" "$SERVER_NAME"

      else

          blcli_execute Job addTargetServer "$JOB_KEY" "$SERVER_NAME"

      fi

       

      blcli_storeenv JOB_KEY

       

      #blcli_execute BatchJob executeJobAndWait $JOB_KEY

      blcli_execute $JOBTYPE executeJobAndWait $JOB_KEY

      blcli_destroy

       

       

      When the APPserver launch this script the JOB or BatchJOB is launched multiple times on the same machine.

       

      Machine Name WEHSTG4061Machine Name WEHSTG4061
      Capture-1.jpgCapture-2.jpg
      same Bundle run in same time on a same machinesame Bundle run in same time on a same machine

       

      Do you have an idea ? We have do an error in our script ?

       

      Thx for your help.

       

       

        • 1. Re: [SCRIPT] - NSH from APPserver to Bladelogic
          Bill Robinson

          where are you running the script from ?

           

          i have seen this before w/ the executeJobAndWait where the blcli -> appserver connection gets cut off (probably an idle timeout on a network device between the two) and then the job gets re-started.  in your case it looks like every 5 min.  however we were never able to reproduce the problem in house.

           

          Instead of using executeJobAndWait you can use what i outline here:  Run a Job from the BLCLI and wait for it to complete  w/ the scheduleid and polling.

          • 2. Re: [SCRIPT] - NSH from APPserver to Bladelogic
            Yann Michalak

            Thx @

             

            We have try to modify our script like this yesterday with yours inputs, without success :

             

             

            SERVICE_PROFILE_NAME=$1

            USERNAME_USER=UserName

            AUTH_TYPE=SRP

            PASSWORD_USER=MyPassword

            APP_SERVER_HOST=VIP-LB

            ROLE_NAME=MyRole

            SERVER_NAME=$2

             

            # JOB_GROUP = Job Group containing job to execute

            #JOB_GROUP="/Application Deployments"

            JOB_GROUP=$3

            #JOB_GROUP=`echo $JOB_GROUP | sed -e "s/%20/ /g"`

             

            # JOB_NAME = Name of Job to execute

            #JOB_NAME="IIS"

            JOB_NAME=$4

            #JOB_NAME=`echo $JOB_NAME | sed -e "s/%20/ /g"`

             

            # set up connection

            blcred cred -acquire -profile "$SERVICE_PROFILE_NAME" -username "$USERNAME_USER" -password "$PASSWORD_USER"

            blcli_setoption serviceProfileName $SERVICE_PROFILE_NAME

            blcli_setoption authType $AUTH_TYPE

            blcli_setoption userName $USERNAME_USER

            blcli_setoption password $PASSWORD_USER

            blcli_setoption appserverHost $APP_SERVER_HOST

            blcli_setoption roleName $ROLE_NAME

            blcli_connect

             

             

            blcli_execute BatchJob getDBKeyByGroupAndName "$JOB_GROUP" "$JOB_NAME"

            blcli_storeenv JOB_KEY

            #  ASSET TEST Sprint 3

            blcli_execute Job executeJobAndReturnScheduleID ${JOB_KEY}

            blcli_storeenv JOB_SCHEDULE_ID

            JOB_STATUS="INCOMPLETE"

            COUNT=1

            while [[ -n "${${JOB_STATUS//COMPLETE}//$'\n'}" ]] && [[ ${COUNT} -le 100 ]]

                 do

                 sleep 10

                 blcli_execute JobRun getJobRunStatusByScheduleId ${JOB_SCHEDULE_ID}

                 blcli_storeenv JOB_STATUS

                 echo "Schedule ${JOB_SCHEDULE_ID} status is: ${JOB_STATUS//$'\n'/ }"

                 let COUNT+=1

            done

             

            #  ASSET TEST Sprint 3 : Find ID

            blcli_execute JobRun findByScheduleId ${JOB_SCHEDULE_ID}

            blcli_execute JobRun getJobRunId

            blcli_storeenv JOB_RUN_ID

            #  ASSET TEST Sprint 3 : Find KEY

            blcli_execute JobRun findByScheduleId ${JOB_SCHEDULE_ID}

            blcli_execute JobRun getJobRunKey

            blcli_storeenv JOB_RUN_KEY

              

             

            #Clear old target servers from batch job

            blcli_execute Job clearTargetServers $JOB_KEY

            blcli_storeenv JOB_KEY

             

            blcli_execute BatchJob addNamedServerToJobByJobDBKey "$JOB_KEY" "$SERVER_NAME"

            blcli_storeenv JOB_KEY

             

             

            blcli_execute BatchJob executeJobAndWait $JOB_KEY

            #  ASSET TEST Sprint 3

            blcli_storeenv JOB_RUN_KEY

            JOB_IS_RUNNING="true"

            while [[ "${JOB_IS_RUNNING}" = "true" ]]

                    do

                    sleep 10

                    blcli_execute JobRun getJobRunIsRunningByRunKey ${JOB_RUN_KEY}

                    blcli_storeenv JOB_IS_RUNNING

                    echo "${JOB_IS_RUNNING}"

            done

            blcli_destroy

             

             

            Same error the BUNDLE is launched each 5 minutes :

             

            Capture-5.jpg

             

            where are you running the script from ?

            - From an appserver with bladelogic console installed.

            • 3. Re: [SCRIPT] - NSH from APPserver to Bladelogic
              Bill Robinson
              We have try to modify our script like this yesterday with yours inputs, without success :

               

              really?  because i still see this call in the script:

              blcli_execute BatchJob executeJobAndWait $JOB_KEY

              so no, you didn't modify the script to use only polling.

              • 4. Re: [SCRIPT] - NSH from APPserver to Bladelogic
                Yann Michalak

                Hello ;-)

                 

                Correct but without

                blcli_execute BatchJob executeJobAndWait $JOB_KEY

                we have the same problem.....Same job is launched twice on the same machine at same time :

                 

                bl.png

                 

                 

                SERVICE_PROFILE_NAME=$1

                USERNAME_USER=UserName

                AUTH_TYPE=SRP

                PASSWORD_USER=MyPassword

                APP_SERVER_HOST=VIP-LB

                ROLE_NAME=MyRole

                SERVER_NAME=$2

                 

                 

                echo "Script : DeployJob"

                 

                # set up connection

                blcred cred -acquire -profile "$SERVICE_PROFILE_NAME" -username "$USERNAME_USER" -password "$PASSWORD_USER"

                blcli_setoption serviceProfileName $SERVICE_PROFILE_NAME

                blcli_setoption authType $AUTH_TYPE

                blcli_setoption userName $USERNAME_USER

                blcli_setoption password $PASSWORD_USER

                blcli_setoption appserverHost $APP_SERVER_HOST

                blcli_setoption roleName $ROLE_NAME

                blcli_connect

                 

                JOB_KEY=$2

                SERVER_NAME=$3

                JOBTYPE=$4

                 

                #Clear old target servers from batch job

                blcli_execute Job clearTargetServers $JOB_KEY

                blcli_storeenv JOB_KEY

                 

                if [[ ${JOBTYPE} == "BatchJob" ]] || [[ "${JOBTYPE}" == "BatchJob" ]];then

                    echo "Batch job in DeployJob"

                    blcli_execute BatchJob addNamedServerToJobByJobDBKey "${JOB_KEY}" "${SERVER_NAME}"

                    echo "End of Batch job in DeployJob"

                else

                    blcli_execute Job addTargetServer "${JOB_KEY}" "${SERVER_NAME}"

                fi

                 

                blcli_storeenv JOB_KEY

                 

                #blcli_execute BatchJob executeJobAndWait $JOB_KEY

                #blcli_execute $JOBTYPE executeJobAndWait $JOB_KEY

                 

                echo "\nJob Key : ${JOB_KEY}"

                 

                blcli_execute $JOBTYPE executeJobAndReturnScheduleID "${JOB_KEY}"

                blcli_storeenv JOB_SCHEDULE_ID

                echo "Job Schedule ID : ${JOB_SCHEDULE_ID}"

                 

                blcli_execute JobRun findByScheduleId ${JOB_SCHEDULE_ID}

                blcli_execute JobRun getJobRunKey

                blcli_storeenv JOB_RUN_KEY

                echo "Job Run Key 1 : ${JOB_RUN_KEY}"

                 

                blcli_execute Job executeJobAndWaitForRunID "${JOB_KEY}"

                blcli_storeenv JOB_RUN_KEY

                echo "\nJob Run Key 2 : ${JOB_RUN_KEY}"

                sleep 20

                JOB_IS_RUNNING="true"

                while [[ "${JOB_IS_RUNNING}" == "true" ]]

                do

                    sleep 10

                    echo "\nStill running ?"

                    blcli_execute JobRun getJobRunIsRunningByRunKey "${JOB_RUN_KEY}"

                    blcli_storeenv JOB_IS_RUNNING

                 

                done

                 

                blcli_destroy

                 

                 

                 

                Ahahahahahaaaaaaaaaaaaaaaaaaaaa

                • 5. Re: [SCRIPT] - NSH from APPserver to Bladelogic
                  Bill Robinson

                  maybe that's because you are doing this:

                   

                  blcli_execute $JOBTYPE executeJobAndReturnScheduleID "${JOB_KEY}"

                  blcli_storeenv JOB_SCHEDULE_ID

                  echo "Job Schedule ID : ${JOB_SCHEDULE_ID}"

                   

                  blcli_execute JobRun findByScheduleId ${JOB_SCHEDULE_ID}

                  blcli_execute JobRun getJobRunKey

                  blcli_storeenv JOB_RUN_KEY

                  echo "Job Run Key 1 : ${JOB_RUN_KEY}"

                   

                  blcli_execute Job executeJobAndWaitForRunID "${JOB_KEY}"

                   

                  -> you are running the same job twice, right after each other.

                  • 6. Re: [SCRIPT] - NSH from APPserver to Bladelogic
                    Yann Michalak

                    YEP ;-)

                     

                    Ok we have changed to :

                     

                    # set up connection

                    blcred cred -acquire -profile "$SERVICE_PROFILE_NAME" -username "$USERNAME_USER" -password "$PASSWORD_USER"

                    blcli_setoption serviceProfileName $SERVICE_PROFILE_NAME

                    blcli_setoption authType $AUTH_TYPE

                    blcli_setoption userName $USERNAME_USER

                    blcli_setoption password $PASSWORD_USER

                    blcli_setoption appserverHost $APP_SERVER_HOST

                    blcli_setoption roleName $ROLE_NAME

                    blcli_connect

                     

                    JOB_KEY=$2

                    SERVER_NAME=$3

                    JOBTYPE=$4

                     

                    #Clear old target servers from batch job

                    blcli_execute Job clearTargetServers $JOB_KEY

                    blcli_storeenv JOB_KEY

                     

                    if [[ ${JOBTYPE} == "BatchJob" ]] || [[ "${JOBTYPE}" == "BatchJob" ]];then

                        echo "Batch job in DeployJob"

                        blcli_execute BatchJob addNamedServerToJobByJobDBKey "${JOB_KEY}" "${SERVER_NAME}"

                        echo "End of Batch job in DeployJob"

                    else

                        blcli_execute Job addTargetServer "${JOB_KEY}" "${SERVER_NAME}"

                    fi

                     

                    blcli_storeenv JOB_KEY

                     

                    #blcli_execute BatchJob executeJobAndWait $JOB_KEY

                    #blcli_execute $JOBTYPE executeJobAndWait $JOB_KEY

                     

                    echo "\nJob Key : ${JOB_KEY}"

                     

                    #blcli_execute $JOBTYPE executeJobAndReturnScheduleID "${JOB_KEY}"

                    #blcli_storeenv JOB_SCHEDULE_ID

                    #echo "Job Schedule ID : ${JOB_SCHEDULE_ID}"

                     

                    #blcli_execute JobRun findByScheduleId ${JOB_SCHEDULE_ID}

                    #blcli_execute JobRun getJobRunKey

                    #blcli_storeenv JOB_RUN_KEY

                    #echo "Job Run Key 1 : ${JOB_RUN_KEY}"

                     

                    blcli_execute Job executeJobAndWaitForRunID "${JOB_KEY}"

                    blcli_storeenv JOB_RUN_KEY

                    echo "\nJob Run Key 2 : ${JOB_RUN_KEY}"

                     

                    JOB_IS_RUNNING="false"

                    while [[ "${JOB_IS_RUNNING}" != "true" ]]

                    do

                        sleep 5

                        echo "\nWarming ended ?"

                        blcli_execute JobRun getJobRunIsRunningByRunKey "${JOB_RUN_KEY}"

                        blcli_storeenv JOB_IS_RUNNING

                    done

                     

                    JOB_IS_RUNNING="true"

                    while [[ "${JOB_IS_RUNNING}" == "true" ]]

                    do

                        sleep 10

                        echo "\nStill running ?"

                        blcli_execute JobRun getJobRunIsRunningByRunKey "${JOB_RUN_KEY}"

                        blcli_storeenv JOB_IS_RUNNING

                    done

                     

                    blcli_destroy

                     

                     

                    but same problem .... OK .... we try differently .... It's possible with NSH Script to create un A RANDOM timer before launch the JOB ?

                    Before the # set up connection Section for example ?

                     

                    With Powershell it's really simple :

                     

                    function Restart-ComputerSoon

                    {

                      param (

                        $Timeframe = 3600

                      )

                      $Timeout = (New-Object System.Random).Next(0,$Timeframe)

                      shutdown.exe /f /r /t $Timeout

                    }

                    Restart-ComputerSoon

                     

                    but with NSH I'm really newbie :-)

                     

                    Do you have an idea ?

                     

                    Thx for your help.

                    • 7. Re: [SCRIPT] - NSH from APPserver to Bladelogic
                      Bill Robinson

                      not sure what powershell or a random timer has to do w/ it.  and i don't think you are reading the blog entry i posted because you keep using different commands.

                       

                      blcli_setoption authType $AUTH_TYPE

                      blcli_setoption userName $USERNAME_USER

                      blcli_setoption password $PASSWORD_USER

                      blcli_setoption appserverHost $APP_SERVER_HOST

                      -> you don't need any of these, since bsa 7.4.

                       

                      blcli_execute Job clearTargetServers $JOB_KEY

                      blcli_storeenv JOB_KEY

                      -> why are you doing this, why not 'Job.executeAgainstServers' ?  because you don't need to alter the job just to run it against some targets.

                       

                      then later you are running the 'is job running' check twice in two separate loops ?  because why ?  in the blog entry i pointed you to, the point was to use the schedule ID and use that to poll on status. you don't seem to be doing that.

                       

                      so a slightly altered version of your script:

                       

                      # set up connection (where are these variables coming from ?
                      blcred cred -acquire -profile "${SERVICE_PROFILE_NAME}" -username "${USERNAME_USER}" -password "${PASSWORD_USER}"
                      #quiet down the blcli output
                      blcli_setjvmoption -Dcom.bladelogic.cli.execute.quietmode.enabled=true
                      blcli_setoption serviceProfileName "${SERVICE_PROFILE_NAME}"
                      blcli_setoption roleName "${ROLE_NAME}"
                      blcli_connect
                      JOB_KEY="${2}"
                      SERVER_NAME="${3}"
                      
                      echo "JobKey: ${JOB_KEY}"
                      echo "Server Name: ${SERVER_NAME}"
                      blcli_execute Job executeAgainstServers ${JOB_KEY} ${SERVER_NAME}
                      blcli_storeenv JOB_SCHEDULE_ID
                      echo "Job Schedule ID : ${JOB_SCHEDULE_ID}"
                      JOB_STATUS="INCOMPLETE"  
                      while [[ -n "${${JOB_STATUS//COMPLETE}//$'\n'}" ]]  
                           do  
                           sleep 10  
                           blcli_execute JobRun getJobRunStatusByScheduleId ${JOB_SCHEDULE_ID}  
                           blcli_storeenv JOB_STATUS  
                           echo "Schedule ${JOB_SCHEDULE_ID} status is: ${JOB_STATUS//$'\n'/ }"  
                      done  
                      blcli_destroy
                      

                       

                       

                      based on the blog entry i posted.  if you run just the above, do you still see the job starting multiple times in quick succession ?

                      • 8. Re: [SCRIPT] - NSH from APPserver to Bladelogic
                        Yann Michalak

                        Your support is greatly appreciated Bill Robinson

                         

                        We have find a solution and it's works....

                         

                        SERVICE_PROFILE_NAME=MYprofilBL

                        USERNAME_USER=MyBLuser

                        AUTH_TYPE=SRP

                        PASSWORD_USER=MyBLuserPASSWORD

                        APP_SERVER_HOST=MyBLuserLoadBalacing

                        ROLE_NAME=MyBLrole

                         

                        # set up connection

                        blcred cred -acquire -profile "$SERVICE_PROFILE_NAME" -username "$USERNAME_USER" -password "$PASSWORD_USER"

                        blcli_setoption serviceProfileName $SERVICE_PROFILE_NAME

                        blcli_setoption authType $AUTH_TYPE

                        blcli_setoption userName $USERNAME_USER

                        blcli_setoption password $PASSWORD_USER

                        blcli_setoption appserverHost $APP_SERVER_HOST

                        blcli_setoption roleName $ROLE_NAME

                        blcli_connect

                         

                         

                        SERVER_NAME="${3}"

                        JOB_GROUP="${5}"

                        JOB_NAME="${6}"

                        JOB_TYPE="${4}"

                         

                        blcli_execute $JOB_TYPE getDBKeyByGroupAndName "$JOB_GROUP" "$JOB_NAME"

                        blcli_storeenv JOB_KEY

                         

                        #Clear old target servers from batch job

                        #blcli_execute Job clearTargetServers $JOB_KEY

                        blcli_execute Job executeAgainstServers $JOB_KEY "$SERVER_NAME"

                        blcli_storeenv JOB_SCHEDULE_ID

                         

                        echo "Job Schedule ID : ${JOB_SCHEDULE_ID}" 

                        JOB_STATUS="INCOMPLETE"   

                        while [[ -n "${${JOB_STATUS//COMPLETE}//$'\n'}" ]]   

                             do   

                             sleep 10   

                             blcli_execute JobRun getJobRunStatusByScheduleId ${JOB_SCHEDULE_ID}   

                             blcli_storeenv JOB_STATUS   

                             echo "Schedule ${JOB_SCHEDULE_ID} status is: ${JOB_STATUS//$'\n'/ }"   

                        done 

                         

                        #blcli_execute $JOBTYPE executeJobAndWait $JOB_KEY

                        blcli_destroy

                         

                         

                         

                        We have just the check Status on Batchjob....who not work.... We have try with :

                         

                         

                        echo "Job Schedule ID : ${JOB_SCHEDULE_ID}" 

                        JOB_STATUS="INCOMPLETE"   

                        while [[ -n "${${JOB_STATUS//COMPLETE}//$'\n'}" ]]   

                             do   

                             sleep 10   

                             blcli_execute JobRun getJobRunStatusByScheduleId ${JOB_SCHEDULE_ID}   

                             blcli_storeenv JOB_STATUS   

                             echo "Schedule ${JOB_SCHEDULE_ID} status is: ${JOB_STATUS//$'\n'/ }"   

                        done 

                         

                         

                        Also :

                         

                         

                        JOB_IS_RUNNING="false"

                        while [[ "${JOB_IS_RUNNING}" != "true" ]]

                        do

                            sleep 5

                            echo "\nWarming ended ?"

                            blcli_execute JobRun getJobRunIsRunningByRunKey "${JOB_SCHEDULE_ID }"

                            blcli_storeenv JOB_IS_RUNNING

                        done

                         

                        JOB_IS_RUNNING="true"

                        while [[ "${JOB_IS_RUNNING}" == "true" ]]

                        do

                            sleep 10

                            echo "\nStill running ?"

                            blcli_execute JobRun getJobRunIsRunningByRunKey "${JOB_SCHEDULE_ID }"

                            blcli_storeenv JOB_IS_RUNNING

                        done

                         

                        It's possible to check if BatchJob or Job have a State :

                         

                        - Running / Complete

                        and

                        - Successfull / Failed

                         

                        ????

                         

                        @++

                        • 9. Re: [SCRIPT] - NSH from APPserver to Bladelogic
                          Bill Robinson

                          you know that you don't need these right:

                          blcli_setoption authType $AUTH_TYPE

                          blcli_setoption userName $USERNAME_USER

                          blcli_setoption password $PASSWORD_USER

                          blcli_setoption appserverHost $APP_SERVER_HOST

                          they are doing nothing in your script.

                           

                          so, after you exit the while loop, you have the job schedule id.  and because the while loop has exited, you know the job is no longer running, so why are you running this:

                          blcli_execute JobRun getJobRunIsRunningByRunKey

                          you don't need to check that it's still running, the while loop did that.

                           

                           

                          It's possible to check if BatchJob or Job have a State :

                           

                          - Running / Complete

                          this is already done in the while loop.

                           

                          - Successfull / Failed

                          well, did you read the blog post?  first you need to convert the schedule id into a job run key or job run id:

                          I can run something like this to convert the scheduled into a job run id or job run key:

                          blcli_execute JobRun findByScheduleId ${JOB_SCHEDULE_ID} 

                          blcli_execute JobRun getJobRunId 

                          blcli_storeenv JOB_RUN_ID 

                          or

                          blcli_execute JobRun findByScheduleId ${JOB_SCHEDULE_ID} 

                          blcli_execute JobRun getJobRunKey 

                          blcli_storeenv JOB_RUN_KEY

                          so you should figure out what command you want to run to check if the job run had errors or warnings or whatever you want to check for and then choose the appropriate sequence of commands that will get you what you need to run the check you want.

                          • 10. Re: [SCRIPT] - NSH from APPserver to Bladelogic
                            Yann Michalak

                            Thx....

                             

                            well, did you read the blog post?

                             

                            Yes of course we have see the convert but we have an error "Mistatching arguments"

                             

                            We want just retrieve state RUNNING and COMPLETE for DeployJOB & BatchJob

                             

                            This works for a DEPLOYJOB :

                             

                            # ASSET -

                            blcli_execute $JOB_TYPE getDBKeyByGroupAndName "$JOB_GROUP" "$JOB_NAME"

                            blcli_storeenv JOB_KEY

                             

                             

                            # ASSET -

                            blcli_execute Job executeAgainstServers $JOB_KEY "$SERVER_NAME"

                            blcli_storeenv JOB_SCHEDULE_ID

                             

                            #ASSET - Check status of deployment 

                            # WAIT FOR JOB TO ENTER RUNNING STATE

                            sleep 10

                            JOB_STATUS="INCOMPLETE"   

                            while [[ -n "${${JOB_STATUS//COMPLETE}//$'\n'}" ]]   

                            do

                            sleep 10

                            blcli_execute JobRun getJobRunStatusByScheduleId ${JOB_SCHEDULE_ID}

                            blcli_storeenv JOB_STATUS

                            echo "Schedule ${JOB_SCHEDULE_ID} status is: ${JOB_STATUS//$'\n'/ }"

                            done

                             

                            but no for a BATCHJOB

                            ++

                            • 11. Re: [SCRIPT] - NSH from APPserver to Bladelogic
                              Yann Michalak

                              OK now it's works ....Thx for your help & your patience Bill Robinson :

                               

                              # parameter list

                              # SERVICE_PROFILE_NAME = BL Service Profile Name for connecting

                              # USERNAME_USER=BladeLogic login username

                              # AUTH_TYPE=Authentication method used for login

                              # PASSWORD_USER=BladeLogic password for username

                              # APP_SERVER_HOST=BladeLogic App Server host

                              # ROLE_NAME=The role the username belongs to

                               

                              SERVICE_PROFILE_NAME=BLprofile

                              USERNAME_USER=BLuser

                              AUTH_TYPE=BLauth

                              PASSWORD_USER=BLpsw

                              APP_SERVER_HOST=BLvip

                              ROLE_NAME=BLrole

                               

                              # set up connection

                              blcred cred -acquire -profile "$SERVICE_PROFILE_NAME" -username "$USERNAME_USER" -password "$PASSWORD_USER"

                              blcli_setoption serviceProfileName $SERVICE_PROFILE_NAME

                              blcli_setoption authType $AUTH_TYPE

                              blcli_setoption userName $USERNAME_USER

                              blcli_setoption password $PASSWORD_USER

                              blcli_setoption appserverHost $APP_SERVER_HOST

                              blcli_setoption roleName $ROLE_NAME

                              blcli_connect

                               

                              EXECUTEJOBAGAINSTSERVERUNTILSUCCESSFUL()

                               

                              {

                              # ENGINEER: MATT RAGLAND Matthew_Ragland@aotx.uscourts.gov

                              # DATE & COMMENTS: 01/25/2017 - INITIAL CREATION

                              # USAGE: USE THIS TO EXECUTE A JOB AGAINST A SERVER AND RUN IT A VARIANT NUMBER OF TIMES OR UNTIL IT IS SUCCESSFUL

                              # EXECUTEJOBAGAINSTSERVERUNTILSUCCESSFUL [TARGET] [JOBTYPE] [JOBLOCATION] [JOBNAME] [TRIES]

                              # EXECUTEJOBAGAINSTSERVERUNTILSUCCESSFUL MYSERVER NSHScriptJob "/Jobs Workspace/Administrative Jobs" "Autolic NSH Script Job" 5

                              # MYSERVER represents the servername of the target you wish to execute job against

                              # NSHScriptJob represents the type of job you are executing, refer to the list below

                              # JOBTYPES

                              # AclPushJob, AgentInstallerJob, Atrium2BlSyncJob, AuditJob, BatchJob, DeployJob, DiscoveryJob, NSHScriptJob, PatchDownloadJob,

                              # PatchingJob, PatchRemediationJob, ProvisionJob, PublishProductCatalogJob, SCAPComplianceJob, SnapshotJob, UCSProvisionJob,

                              # UpdateServerPropertyJob, VirtualGuestJob, VMCaptureJob, VMImportJob, VSMDiscoveryJob, WorkflowJob

                              # "/Jobs Workspace/Administrative Jobs" refers to the path of the job in the BSA console

                              # "Autolic NSH Script Job" refers to the name of the job in the BSA console

                              # 5 refers to the number of times the job will be tried before we fail **NOTE - if the job succeeds on the first try, it will

                              # not retry additional times, it will just simply move on

                              # OBTAIN INPUTS

                               

                              #ASSET - Variable order from INSTALLSOFTWARE.PS1

                              TARGET="$1"

                              JOBTYPE="$2"

                              JOBLOCATION="$3"

                              JOBNAME="$4"

                              TRIES="$5"

                               

                              #ASSET - Function EXECUTEJOBAGAINSTSERVERUNTILSUCCESSFUL

                              ATTEMPT=1

                              RESULT=true

                              echo "Executing ${JOBNAME} against ${TARGET}"

                                  while [ "${RESULT}" = 'true' ]; do

                                      if [ ${ATTEMPT} -gt ${TRIES} ]; then

                                          echo "${JOBNAME} has failed ${TRIES} times, return..."

                                          return 1

                                      fi  

                                      blcli_execute ${JOBTYPE} getDBKeyByGroupAndName "${JOBLOCATION}" "${JOBNAME}"

                                      blcli_storeenv JOBKEY

                                      blcli_execute Job executeAgainstServersForRunID "${JOBKEY}" "${TARGET}"

                                      blcli_storeenv RUNKEY

                               

                                  

                              # WAIT FOR JOB TO ENTER RUNNING STATE

                                      sleep 10

                                      ISRUNNING=true

                                      while [ "${ISRUNNING}" = 'true' ]; do

                                          blcli_execute JobRun getJobRunIsRunningByRunKey "${RUNKEY}"

                                          blcli_storeenv ISRUNNING

                                          sleep 30

                                      done

                               

                                      blcli_execute JobRun getJobRunHadErrors "${RUNKEY}"

                                      blcli_storeenv RESULT

                                      echo "${JOBNAME} hadErrors:${RESULT}"

                                      if [ "${RESULT}" = 'false' ]; then

                                          return 0

                                      fi

                                      ((ATTEMPT++))

                                  done

                              }

                               

                              #ASSET - Variable order from FUNCTION EXECUTEJOBAGAINSTSERVERUNTILSUCCESSFUL

                              JOB_KEY=$2

                              SERVER_NAME="${3}"

                              JOB_TYPE="${4}"

                              # JOB_GROUP = Job Group containing job to execute

                              JOB_GROUP="${5}"

                              # JOB_NAME = Name of Job to execute

                              JOB_NAME="${6}"

                              # EXECUTEJOBAGAINSTSERVERUNTILSUCCESSFUL [TARGET] [JOBTYPE] [JOBLOCATION] [JOBNAME] [TRIES]

                              # EXECUTEJOBAGAINSTSERVERUNTILSUCCESSFUL MYSERVER NSHScriptJob "/Jobs Workspace/Administrative Jobs" "Autolic NSH Script Job" 5

                                

                              EXECUTEJOBAGAINSTSERVERUNTILSUCCESSFUL ${SERVER_NAME} ${JOB_TYPE} "$JOB_GROUP" "$JOB_NAME" 5

                              • 12. Re: [SCRIPT] - NSH from APPserver to Bladelogic
                                Bill Robinson

                                We want just retrieve state RUNNING and COMPLETE for DeployJOB & BatchJob

                                yes - you keep saying that.  why do you think the loop below does not do that ?

                                 

                                 

                                while [[ -n "${${JOB_STATUS//COMPLETE}//$'\n'}" ]]   

                                     do   

                                     sleep 10   

                                     blcli_execute JobRun getJobRunStatusByScheduleId ${JOB_SCHEDULE_ID}   

                                     blcli_storeenv JOB_STATUS   

                                     echo "Schedule ${JOB_SCHEDULE_ID} status is: ${JOB_STATUS//$'\n'/ }"   

                                done

                                have you looked at the docs for this command: getJobRunStatusByScheduleId ?  why do you think it's not telling you if the job is running or not ?

                                This works for a DEPLOYJOB :

                                and the above loop should work just fine for a batch job.  does not not ?